diff --git a/models/protocols/SendGridProtocol.cfc b/models/protocols/SendGridProtocol.cfc index f3d4da6..4202145 100644 --- a/models/protocols/SendGridProtocol.cfc +++ b/models/protocols/SendGridProtocol.cfc @@ -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" );