sirhc
BRBuildShip + Rowy
•Created by sirhc on 9/10/2024 in #❓・buildship-help
sendgrid attachments
@Gaurav Chadha @Luis any update on this?
9 replies
BRBuildShip + Rowy
•Created by sirhc on 9/10/2024 in #❓・buildship-help
sendgrid attachments
@Gaurav Chadha @Luis hey, cheers for looking into this
9 replies
BRBuildShip + Rowy
•Created by sirhc on 9/10/2024 in #❓・buildship-help
sendgrid attachments
Dunno if the images attached or not, see below:
import sgMail from "@sendgrid/mail";
import fs from "fs";
export default async function sendEmailWithSendgrid({
apiKey,
fromAddress,
fromName,
toAddress,
tracking,
templateId,
templateConfig,
attachments
}: NodeInputs, {
logging
}: NodeScriptOptions, ): NodeOutput {
sgMail.setApiKey(apiKey);
const msg = {
to: toAddress,
from: fromAddress,
subject: fromName,
templateId: templateId,
dynamicTemplateData: templateConfig,
trackingSettings: {
clickTracking: {
enable: tracking
},
openTracking: {
enable: tracking
},
subscriptionTracking: {
enable: tracking
},
},
attachments: attachments ? attachments.map(filePath => ({
content: fs.readFileSync(${process.env.BUCKET_FOLDER_PATH}/${filePath}).toString('base64'),
filename: filePath.split('/').pop(),
type: 'application/octet-stream',
disposition: 'attachment'
})) : []
};
try {
await sgMail.send(msg);
logging.log("Email sent");
return "Message Sent!";
} catch (error) {
logging.error(error);
throw error;
}
}
9 replies