LogoLogo
Printed BookDownload BookCFML SupportCFML Videos
  • Introduction
  • Intro
    • Welcome
      • Author
      • About This Book
    • What is ColdFusion (CFML)
    • CommandBox CLI
    • Instructions & Interpreters
  • CFML Language
    • Syntax
    • Comments
    • Variables
    • Variable Scopes
    • Operators
    • Null & Nothingness
    • Strings
    • JSON
    • Numbers
    • Arrays
    • Structures
    • Database Queries
    • Conditionals
    • Exception Management
    • Components
      • Properties
      • Functions
      • Static Constructs
      • Final Constructs
      • Abstract Constructs
      • Interfaces
    • Closures
    • Code Locking
    • Threading
    • Includes
    • Java Integration
  • Beyond The 100
    • Beyond The 100
    • Application.cfc
    • File Handling
    • Image Manipulation
    • HTTP/S Calls
    • Sending Emails
    • Asynchronous Programming
  • Extra Credit
    • MVC
    • Dependency Injection
    • Security Guide
Powered by GitBook

Support Us

  • Become a Patreon
  • Contribute
  • CFCasts

Social Media

  • LinkedIn
  • Facebook
  • Twitter

Ortus Solutions, Corp

On this page
  • Query Binding
  • Sending Attachments

Was this helpful?

Edit on GitHub
  1. Beyond The 100

Sending Emails

PreviousHTTP/S CallsNextAsynchronous Programming

Last updated 1 year ago

Was this helpful?

CFML gives you the cfmail tag/construct to easily send email in text or HTML format without any ceremony. Just register your mail servers in the administrators or the Application.cfc and you are ready to start sending emails in a jiffy!

cfmail( 
  subject="Your Order", 
  from="myshop@ortus.com", 
  to="whatever@gmail.com,another@gmail.com",
  bcc="orders@ortus.com"
  type="HTML"
){
  // body of the email.
  writeOutput( 'Hi there,' );
  writeOutput( 'This mail is sent to confirm that we have received your order.' );
};

The cfmail tag/construct has tons of attributes, so check them out in the docs

Query Binding

You can even bind the mail construct with a query, and the engine will send as many emails as rows in the query for you:

var qData = userService.getNewUsers();
cfmail( 
  subject="Welcome to FORGEBOX!", 
  from="myshop@ortus.com", 
  to="#qData.email#",
  query=qData
){
  writeOutput( "
    Dear #qData.name#,
    
    Welcome to your FORGEBOX account! Play and just do it!
  ")
};

Sending Attachments

You can also send attachments to your email destinations very easily using the mimeattach attribute or via the child cfmailparam() construct, which allows you to send multiple attachments, or headers.

cfmail( 
  subject="Your Order", 
  from="myshop@ortus.com", 
  to="whatever@gmail.com,another@gmail.com",
  bcc="orders@ortus.com"
  mimeattach=expandPath( "/my/path/attach.pdf" );
){
  // body of the email.
  writeOutput( 'Hi there,' );
  writeOutput( 'This mail is sent to confirm that we have received your order.' );
};

cfmail( subject="Attachments", to="you@domain.com", from="me@domain.com" ) {
	cfmailparam( name="Reply-To", value="me@domain.com" );
	cfmailparam( file="c:\files\readme.txt" );
	cfmailparam( file="c:\files\logo.gif" );
}

More in-depth information can be found here:

https://cfdocs.org/cfmail
https://helpx.adobe.com/coldfusion/developing-applications/using-external-resources/sending-and-receiving-e-mail/sending-e-mail-messages.html