Sending Emails
Mail - How to send a Mail
The following example shows you how you can send a mail using <cfmail>.
In order to send and email, you need to provide the mail server configuration.
- Define a default Mail server in the Lucee Administrator /
CFConfig.json
- Configure an application specific mail server in Application.cfc / <cfapplication>
- Pass the server details directly using <cfmail> attributes,
server
,port
etc
Tags
<cfmail subject="Your Order" from="whatever@lucee.org" to="whatever@gmail.com">
Hi there,
This mail is sent to confirm that we have received your order.
</cfmail>
Script
mail subject="Your Order" from="whatever@lucee.org" to="whatever@gmail.com" {
writeOutput('Hi there,');
writeOutput('This mail is sent to confirm that we have received your order.');
};
That is all you need to do to send a mail.
Spooling
By default Lucee spools mails and sends them out via a background thread, for better performance.
If you need to send the mail immediately, or need catch any SMTP errors, use async="false"
which will send the email immediately and throw an errors encountered which will otherwise be caught and logged to the remoteclient.log
mail subject="Your Order" from="whatever@lucee.org" to="whatever@gmail.com" async="false" {
writeOutput('Hi there,');
writeOutput('This mail is sent to confirm that we have received your order.');
};