BoxLang 🚀 A New JVM Dynamic Language Learn More...
This is a ColdFusion Wrapper written to interact with the Postmark API for transactional emails.
Developed by Matt Gifford (aka coldfumonkeh)
Got a lot out of this package? Saved you time and money?
Share the love and visit Matt's wishlist: http://www.amazon.co.uk/wishlist/B9PFNDZNH4PY
This package requires ColdFusion 9+ or Lucee 4.5+
Please note that the tests require ColdFusion 10+ or Lucee 4.5+
You will need a valid Postmark account and an associated account token to interact with the API.
The API wrapper covers all of the methods available within the API. Here's a short sample of what can be achieved:
var oPostmark = new Postmark( accountToken='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' );
// List servers associated with the account
var servers = oPostmark.listServers();
// Get details on a specific server
var server = oPostmark.getServer( serverId='xxxxxxx' );
// Send an email with attachments
oPostmark.sendEmail(
serverToken='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
From='[email protected]',
To='[email protected]',
subject='Your awesome email subject line here',
TextBody='This is the email email.',
HtmlBody='<p>This is the email body</p>',
attachments=[
{name='Text File', srcfile='/attachments/test.txt'},
{name='Image', srcfile='/attachments/something.png'}
]
);
// Send batch emails
oPostmark.sendBatchEmails(
serverToken='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
emailData = [
{
From='[email protected]',
To='[email protected]',
subject='First Batch Email',
TextBody='This is an email.',
attachments=[
{name='Text File', srcfile='/attachments/test.txt'},
{name='Image', srcfile='/attachments/something.png'}
]
},
{
From='[email protected]',
To='[email protected]',
subject='Second Batch Email',
TextBody='This is an email .'
}
]
);
// Validate a template
oPostmark.validateTemplate(
servertoken = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
Subject = "{{##company}}{{name}}{{/company}} {{subjectHeadline}}",
HtmlBody = "{{##company}}{{address}}{{/company}}{{##each person}} {{name}} {{/each}}",
TextBody = "{{##company}}{{phone}}{{/company}}{{##each person}} {{name}} {{/each}}",
TestRenderModel: {
"userName": "bobby joe"
}
);
// Send an email using a template
oPostmark.sendEmailWithTemplate(
serverToken = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
templateId = 'xxxxxxx',
TemplateModel = {
'user_name' = 'John Smith',
'company' = {
'name' = 'ACME'
}
},
from = '[email protected]',
to = '[email protected]'
);
This CF wrapper can be installed as standalone or as a ColdBox Module. Either approach requires a simple CommandBox command:
box install postmark
Then follow either the standalone or module instructions below.
This wrapper will be installed into a directory called postmark
and then can be instantiated via new postmark.Postmark()
with the following constructor arguments:
accountToken = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
This package also is a ColdBox module as well. The module can be configured by creating a postmark
configuration structure in your application configuration file: config/Coldbox.cfc with the following settings:
postmark = {
accountToken = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
};
Then you can leverage the CFC via the injection DSL: postmark@postmark"
The MIT License (MIT)
Copyright (c) 2017-2022 Matt Gifford
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
$
box install postmark