Api sendgrid com v3 mail send

Here is an example of how to send an email using the SendGrid API v3:

Step 1: Create a SendGrid account and obtain an API key

Step 2: Install the SendGrid API client library

Step 3: Set up your SendGrid API credentials

sgMail.setApiKey(process.env.SENDGRID_API_KEY);

* Replace `process.env.SENDGRID_API_KEY` with your actual SendGrid API key.

**Step 4: Send an email using the SendGrid API**

* Create a new file called `send-email.js` and add the following code:

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

const msg = { to: '[email protected]', from: '[email protected]', subject: 'Hello from SendGrid!', text: 'Hello from SendGrid!', html: 'Hello from SendGrid!' };

sgMail.send(msg);

* Replace `[email protected]` and `[email protected]` with the actual email addresses you want to use.

**Step 5: Run the script**

* Run the `send-email.js` script using Node.js:

node send-email.js

* The email should be sent successfully using the SendGrid API.

Here is the complete code:

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

sgMail.setApiKey(process.env.SENDGRID_API_KEY);

// send-email.js const sgMail = require('./sendgrid');

const msg = { to: '[email protected]', from: '[email protected]', subject: 'Hello from SendGrid!', text: 'Hello from SendGrid!', html: 'Hello from SendGrid!' };

sgMail.send(msg);


Make sure to replace the `SENDGRID_API_KEY` environment variable with your actual SendGrid API key.