Eric Peterson

December 14, 2017

Spread the word

Share your thoughts

ForgeBox is your first stop for when you need some new functionality for your application, be that a utility library, an SDK, a framework, or something else. Today we'll take a look at one of the tools for helping manage sending emails — [cbmailservices](


cbmailservices provides a protocol-based service to send emails as well as mail merge functionality to easily customize emails.

But what about good 'ole cfmail? Well, you can still use it! cbmailservices ships with a CFMailProtocol which will delegate back to cfmail for sending your emails.

You might wonder why you would even use this module? Let me give you two reasons:

Mail Merge

Mail merging lets you specify an email template with tokens that can be replaced per email. This lets you tailor your emails to each user, company, or use case you find.

Here's an example of the mail merging capabilitys of cbmailservices:

var mailService = getInstance( "mailService@cbmailservices" );
var mail = mailService.newMail(
    to = "",
    subject = "Mail Services Rock",
    bodyTokens = {
        user = "John",
        product = "cbmailservices",
        link = event.buildLink( "view.cbmailservices" )
    body = "

Dear @user@,

Thank you for downloading @product@. Have a great day!


" ); mailService.send( mail );

This will send the following email:

<p>Dear John,</p>
<p>Thank you for downloading cbmailservices.  Have a great day!</p>
<p><a href=""></a></p>


A cbmailservices protocol defines how to send an email. This can be through good 'ole cfmail, third party mail services like Postmark and SendGrid, or even just locally to your file system or the console output.

Even better, with ColdBox's environment detection, you can set different protocols for each environment. Here's what a sample config/ColdBox.cfc file might look like:

function configure() {
    mailsettings = {
        tokenMarker = "@",
        protocol = {
            class = "cbmailservices.models.protocols.PostmarkProtocol",
            properties = {
                APIKey = getSystemSetting( "POSTMARK_API_KEY" )

function development() {
    mailsettings.protocol = {
        class = "cbmailservices.models.protocols.FileProtocol",
        properties = {
            filePath = "logs",
            autoExpand = true

This configuration will log emails locally to the file system in development and use Postmark to send emails for real in production. Nice!

You can write your own protocols as well and even publish them on ForgeBox like the SendGrid protocol for your favorite email service.

Wrap Up

So head on over to your local CommandBox terminal and give cbmailservices a go!

Add Your Comment

Recent Entries

Elevate Your ColdBox Experience and Skills

Elevate Your ColdBox Experience and Skills

We're thrilled to announce a significant overhaul of our ColdBox training experience to ensure it's nothing short of extraordinary! We've listened closely to your feedback and made significant improvements geared towards transforming you into a ColdBox superhero. Learn What's New!

Maria Jose Herrera
Maria Jose Herrera
February 20, 2024
Ortus Redis Extension v3.3.0 Released!

Ortus Redis Extension v3.3.0 Released!

We are very excited to bring you another release for our Redis Lucee Extension. The most significant feature in this release is the addition of the `` and `redisLock{}` tag, which allows you perform a lock across all instances in a cluster.

Ortus Redis Extension v3.3.0 gives you greater control over concurrent modifications in a distributed environment, utilizing your distributed cache to prevent overlaps!

Jon Clausen
Jon Clausen
February 16, 2024
Introducing: 102 ColdBox HMVC Tips and Tricks

Introducing: 102 ColdBox HMVC Tips and Tricks

In this comprehensive guide, you'll discover a treasure trove of insights tailored to help you build sustainable ColdFusion applications using ColdBox HMVC. But that's not all – we've also included invaluable tips and tricks for companion libraries like CommandBox, WireBox, LogBox, CacheBox, and TestBox. Whether you are a beginner or a seasoned pro, you'll find something to elevate your skills and streamline your development process.

Maria Jose Herrera
Maria Jose Herrera
February 15, 2024