-
Notifications
You must be signed in to change notification settings - Fork 12
Send Messages from Templates
objectivehtml edited this page Dec 22, 2014
·
7 revisions
Postmaster gives developers the ability to send emails programmatically right from your templates. The craft.postmaster.send method will create and send a new Postmaster_TransportModel. The send method accepts two methods.
{
// This is unique id of the service you wish to use to send the message. By default `testing` will be used.
service: 'mandrill',
// A JSON object of settings that will be passed to the service.
serviceSettings: {
apiKey': 'your api key',
trackOpens: true,
trackClicks: true,
autoText: false,
stripQuery: false,
preserveRecipients: false
},
// A JSON object of settings that will be passed to the settings model, which by default is a `Postmaster_EmailModel` object.
settings: {
toName: 'Some Name',
toEmail: test@test.com',
fromName: 'From Name',
fromEmail: 'test@test.com',
replyTo: 'test@test.com',
cc: 'test@test.com',
bcc: 'test@test.com',
subject: 'Some subject...',
htmlBodyTemplate: 'emails/htmlTemplate',
bodyTemplate: 'email/plainTemplate',
}
// A change the type of model used to instantiate the settings. The default value is `Craft\Postmaster_EmailModel`.
settingsModel: 'Craft\Postmaster_EmailModel',
// A JSON object of additional data passed for programmatic purposes to the `Postmaster_TransportModel`.
data: {},
// An optional setting to pass a senderId, also used for programmatic purposes. Omit this option if you have no use for it.
senderId: false,
// Set a date in which to send the message. If the message is post-dated for the future, it will be sent to the queue. Omit this option if you wish to send the message immediately.
sendDate: false,
// If are wanting to send an item from the queue, enter the id here. Most of the time this option does not need to be set.
queueId: false
}
{% set request = {
settings: {
toName: 'Some Name',
toEmail: 'toEmail@test.com',
fromName: 'Some Name',
fromEmail: 'fromEmail@test.com',
subject: 'Some subject here...',
bodyHtmlTemplate: 'emails/testHtml',
bodyTemplate: 'emails/testPlain',
},
service: 'testing',
serviceSettings: {
}
} %}
{% set response = craft.postmaster.send(request, {
'someVar': 'Some Value',
'entry': entry
}) %}