How to send a email with attachment

I have a get request that return a .xlsx file, i need to send this attachment to a specific email, how do i do it?
today i save on my google drive

Hi @allannery02 , are you using a specific email service (like Sendgrid, Mailgun, etc.) to send emails?

If you’re not using a specific service yet, I’m happy to share resources for Sendgrid - their free tier allows for up to 100 emails / day, and they support sending attachments through their email API.

Hi @dylburger would appreciate those resources regarding Sendgrid (or mailgun or any mailing service). Hoping to send an email with an attachment as well. Please advise?

Thanks!

Hi @iansr , this reference from Sendgrid is a great resource. I’d recommend adding a new Node.js code step and connecting the Sendgrid app to that step to get started.

Where Sendgrid references their API key:

sgMail.setApiKey(process.env.SENDGRID_API_KEY);

you can use this, instead:

sgMail.setApiKey(auths.sendgrid.api_key);

By linking a Sendgrid account to that code step, you have access to the linked API key via the auths variable, so there’s no need to add an environment variable.

Where Sendgrid tells you to npm install the Sendgrid Node SDK, there’s no need on Pipedream. You can just include the code that they do in that guide, with the following line:

const sgMail = require('@sendgrid/mail');

and Pipedream will automatically install the npm package for you.

Finally, I’d recommend taking a look at our guide for working with files on Pipedream. Once you save your file to the /tmp directory, you can reference it in the Sendgrid step as an attachment, using the method recommended by Sendgrid.

I opened up a feature request on our backlog to add attachment support to the Sendgrid Send Email action, as well, to make this process easier in the future.

Let me know if that helps or if you have any additional questions!

Thanks @dylburger! It works perfectly.

Signing up with Sendgrid and authenticating the domain took me 48 hours due to a DNS issue, but it was smooth sailing afterwards.

I also had to add an await to the last command to solve this error:

https://pipedream.com/docs/workflows/steps/code/async/#the-problem

All good now, thanks!

1 Like