Nikola Mikasinovic
11/03/2022, 4:48 PMbdw429s
11/03/2022, 4:53 PMbdw429s
11/03/2022, 4:53 PMScott Bennett
11/03/2022, 6:35 PMNikola Mikasinovic
11/04/2022, 7:54 AMScott Bennett
11/04/2022, 2:26 PMcomponent {
this.apiKey = '#application.sparkpostAPIKey#';
public function sendTransactionalEmail(required campaign_id, required string email_to, required string greeting_name, required string message_body, required string subject) {
/* Generate Message Object */
messageObject = {
"campaign_id" = "#arguments.campaign_id#",
"options" = {
"open_tracking" = true,
"click_tracking" = true
},
"recipients" = [
{
"address" = {"email" = "#arguments.email_to#", "name"="#arguments.greeting_name#"},
"substitution_data": {
"subject": "#arguments.subject#",
"greeting_name": "#arguments.greeting_name#",
"message_body": "#arguments.message_body#"
}
}
],
"content" = {
"template_id":"transaction-email-template",
"use_draft_template": false
}
};
cfhttp( getasbinary="never", url="<https://api.sparkpost.com/api/v1/transmissions?num_rcpt_errors=3>", timeout=60, result="httpResp", method="post" ) {
cfhttpparam( name="Content-Type", type="header", value="application/json" );
cfhttpparam( name="Accept", type="header", value="application/json" );
cfhttpparam( name="Authorization", type="header", value=this.APIKey );
cfhttpparam( type="body", value=serializejson(messageObject) );
}
return deserializejson(httpResp.filecontent);
}
}
Scott Bennett
11/04/2022, 2:27 PMScott Bennett
11/04/2022, 2:32 PM