CFMail in script with ColdFusion 9

by 1:15 AM 3 comments
cfmail is script is easy but as the docs are still a bit lacking and there is no mention of the attributes for using mail in script I had a look in the CF9 install directory and in

/opt/ColdFusion9/CustomTags/com/adobe/coldfusion

You will find the cfc's Adobe made to extend script support. I opened up the mail.cfc and worked out how to use the function. Here is a small example.

Of course to, from, subject etc can be strings they don't have to be variables.

3 comments:

  1. Hey Paul,

    You can make it easier to read by using argumentCollection. For example:

    params = {};
    params.to = "you@gmail.com";
    params.from = "me@gmail.com";
    params.subject = "Report";
    params.body = "Here is the report you were after";

    new mail(argumentCollection=params).send();

    ReplyDelete
  2. Is it just me or can you not send complex objects in the body attribute when using mail in script?

    ReplyDelete
  3. @Ryan you can but there is a little more work involved see this post: http://blog.kukiel.net/2011/08/write-dump-in-cfmail-with-cfscript-in.html

    ReplyDelete