Mail Events
The module will register two interception points. PreMailSend and PostMailSend. These interception points are useful to alter the mail object before it gets sent out, and/or perform any functions after the mail gets sent out. An example interceptor would be:
1
component extends="coldbox.system.Interceptor"{
2
​
3
void function configure(){
4
}
5
​
6
boolean function preMailSend( event, data, buffer, rc, prc ){
7
var environment = getSetting('environment');
8
var appName = getSetting('appName');
9
​
10
if(environment eq 'development'){
11
//change recipient if we are on development
12
data.mail.setTo('[email protected]');
13
//prefix the subject if we are on development
14
data.mail.setSubject('<DEV-#appName#> #data.mail.getSubject()#');
15
}
16
}
17
​
18
boolean function postMailSend( event, data, buffer, rc, prc ){
19
if( data.result.error ){
20
//log mail failure here...
21
}
22
}
23
​
24
}
Copied!

preMailSend

Announced before the mail payload is sent to the chosen mailer protocol for sending. This is your last change to influence the payload.

Data Passed

Key
Type
Description
mail
Mail
The mail payload object

postMailSend

Announced after the mail payload has been sent via the mailer protocol of choice.

Data Passed

Key
Type
Description
mail
Mail
The mail payload object
result
struct
The result structure from the mailer protocol. At most it will contain an error boolean key and a messages array.
Last modified 2mo ago
Export as PDF
Copy link
Edit on GitHub