sirhc
sirhc3mo ago

sendgrid attachments

hey there looking for some help with SendGrid dynamic templates sending attachment(s). tried a few things but cant seem to get it working, this is where i am currently at with it. (see images) any help would be great 😃 sorry if this has already been asked
6 Replies
AI Support
AI Support3mo ago
AI Support Bot Information
<@482162699103633418> you can react on the relevant answer (message) with a ✅ in this thread when you think it has been solved, by the bot or by a human! Anyone can react on this message with a ❌ if the GPT bot is unhelpful or hallucinating answers. Please note: Team members will review and answer the questions on best efforts basis.
AI Support
AI Support3mo ago
AI Response
It seems I couldn't find specific information related to sending attachments with SendGrid dynamic templates in the files provided. However, you can refer to the dynamic templates section of the SendGrid documentation to get detailed guidance on how to set up and use dynamic templates. For attaching files, you might want to include the necessary fields in your API request similar to what is shown in the SendGrid API documentation for sending emails with attachments: Make sure your payload includes an attachments array with filename, type, disposition, and content (Base64 encoded) for each attachment you want to include. If you continue facing issues, please send a support request via the in-app support for further assistance. If you need help finding a pre-built template to handle attachments in your workflow, please let me know, and I'll help you locate a suitable one.
BuildShip AI Support
sirhc
sirhcOP3mo ago
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; } }
Gaurav Chadha
Gaurav Chadha2mo ago
cc @Luis, could you please assist here by sharing a sample workflow or a new node to send attachment with sendgrid? https://www.twilio.com/en-us/blog/sending-email-attachments-with-sendgrid
Twilio
Sending Email with Attachments using SendGrid and Node.js
Twilio posts cloud communications trends, customer stories, and tips for building scalable voice and SMS applications with Twilio's APIs.
Luis
Luis2mo ago
Sure thing 👌
sirhc
sirhcOP5w ago
@Gaurav Chadha @Luis hey, cheers for looking into this @Gaurav Chadha @Luis any update on this?