Jul 29, 2009

CFMail in script with ColdFusion 9

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.

4 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. Paul, thanks so much for providing this code. This was truly a difficult tutorial to cut down. CFSCRIPT makes it so easy to send mail. Thanks!

    Evik James

    http://www.franchiseleadmachine.com
    ReplyDelete
  3. Is it just me or can you not send complex objects in the body attribute when using mail in script?
    ReplyDelete
  4. @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