Plugins:MailService
last edited by
aarongreenle
on 21-Oct-2010
|
Exploring the MailService Plugin
Overview
The ColdBox Mail Service used to send emails in an oo fashion
newMail
Get a new Mail payload object, just use config() on it to prepare it.
Returns
- This function returns coldbox.system.beans.Mail
Examples
send
Send an email payload. Returns a struct: [error:boolean,errorArray:array]
Returns
- This function returns struct
Arguments
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
| coldbox.system.beans.Mail | Yes | --- | The mail payload to send. |
Examples
// Used by the email layout to render this e-mail's view rc.emailView = 'Reports/email/scheduledReport'; // Create a new mail object local.Email = MailService.newMail().config( from = getSetting('sendEmailFrom') ,to = arrayToList(local.emailTo) ,subject = 'Scheduled Report: ' & scheduledReport); // Set tokens within the mail object. THe tokens will be evaluated // by the ColdBox Mail Service. Any matching @key@ within the view // will be replaced with the token's value local.Email.setBodyTokens({ timezone = "#local.timeZoneOfServer.getDisplayName()# (#local.timeZoneOfServer.getID()#)" ,reportName = rc.reportTitle ,dateCreated = now() ,reportStatus = (local.reportEmpty) ? 'Nothing to report.' : 'Report Attached' ,username = rc.schedule_users ,frequency = rc.schedule_frequency }); // Add plain text email local.Email.addMailPart(charset='utf-8',type='text/plain',body=local.Renderer.renderLayout("layout.email.plain")); // Add HTML email local.Email.addMailPart(charset='utf-8',type='text/html',body=local.Renderer.renderLayout("layout.email.html")); // Attach a file if a report exists if (!local.reportEmpty) { local.Email.addMailParam(disposition='attachment' ,file=getTempDirectory() & rc.generateResult.filepath ,type='application/vnd.ms-excel'); } // Send the email. MailResult is a boolean. local.mailResult = MailService.send(local.Email);
Related Information from the ColdBox Community
- ColdBox 3 MailService Blog Post by John Whish [Sep 13, 2010]

SideBar
User Login 



