Skip to content

Commit

Permalink
feat: Support for attachments
Browse files Browse the repository at this point in the history
Adds the ability to send attachments through the SendGrid API.

Co-authored-by: Andreas Eppinger <aeppinger@webways.ch>
Co-authored-by: Eric Peterson <elpete@users.noreply.github.com>
  • Loading branch information
3 people committed May 5, 2021
1 parent dd291f3 commit 44f72cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions models/protocols/SendGridProtocol.cfc
Expand Up @@ -100,6 +100,19 @@ component extends="cbmailservices.models.AbstractProtocol" {

body[ "personalizations" ] = [ personalization ];

if ( structkeyExists( mail, 'mailparams' ) && isArray( mail.mailparams ) && ArrayLen( mail.mailparams ) ){
body[ "attachments" ] = mail.mailParams
.filter( function( mailParam ) {
return structKeyExists( mailParam, "file" );
} )
.map( function( mailParam ) {
return {
"content": toBase64( fileReadBinary( mailParam.file ) ),
"filename": listLast( mailParam.file, "/" )
};
} );
}

cfhttp( url = "https://api.sendgrid.com/v3/mail/send", method = "POST" ) {
cfhttpparam( type = "header", name = "Authorization", value="Bearer #getProperty( "apiKey" )#" );
cfhttpparam( type = "header", name = "Content-Type", value="application/json" );
Expand Down

0 comments on commit 44f72cd

Please sign in to comment.