Skip to content

Instantly share code, notes, and snippets.

@jeaguilar
Created April 8, 2016 17:26
Show Gist options
  • Save jeaguilar/d8bc801ab7a744af5ee782a6eddf4477 to your computer and use it in GitHub Desktop.
Save jeaguilar/d8bc801ab7a744af5ee782a6eddf4477 to your computer and use it in GitHub Desktop.
Sendgrid CFML sample using sendgrid-java.jar and tested on Lucee 4.5
<cfscript>
try {
SendGrid = CreateObject("java", "com.sendgrid.SendGrid", expandPath("sendgrid-java.jar")).init('<API KEY>');
Email = CreateObject("java", "com.sendgrid.SendGrid$Email", expandPath("sendgrid-java.jar"));
Email.addTo("<TO ADDRESS>");
Email.setFrom("<FROM ADDRESS>");
Email.setSubject("Hello World, #getTickCount()#");
Email.setHtml("<p>My <strong>first</strong> email with SendGrid Java!</p>");
javaFile = createObject( 'java', 'java.io.File' ).init( '<FILE LOCATION>' );
Email.addAttachment('<FILE NAME>', javaFile);
javaResponse = SendGrid.send(Email);
objResponse = {};
objResponse.Message = javaResponse.getMessage() ?: "";
objResponse.Status = javaResponse.getStatus() ?: "";
objResponse.Code = javaResponse.getCode() ?: "";
writeDump(objResponse);
}
catch (Any excpt) {
writeDump(excpt);
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment