import { ChannelTypeEnum , IEmailOptions , IEmailProvider , ISendMessageSuccessResponse , } from '@notifire/core' ; import sendgridMail from '@sendgrid/mail' ; export class SendgridEmailProvider implements IEmailProvider { id = 'sendgrid' ; channelType = ChannelTypeEnum . EMAIL as ChannelTypeEnum . EMAIL ; constructor ( private config ) { sendgridMail . setApiKey ( this . config . apiKey ) ; } async sendMessage ( options ) { const response = await sendgridMail . send ( { from : options . from || this . config . from , to : options . to , html : options . html , subject : options . subject , substitutions : { } , attachments : options . attachments ?. map ( ( attachment ) => { return { content : attachment . file . toString ( 'base64' ) , filename : attachment . name , type : attachment . mime , } ; } ) , } ) ; return { id : response [ 0 ] ?. headers [ 'x-message-id' ] , date : response [ 0 ] ?. headers ?. date , } ; } }