Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sendgrid/mail

Package Overview
Dependencies
Maintainers
4
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sendgrid/mail

Twilio SendGrid NodeJS mail service

  • 6.5.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by11.41%
Maintainers
4
Weekly downloads
 
Created

What is @sendgrid/mail?

The @sendgrid/mail package is a Node.js client library for sending emails using the SendGrid email service. It provides an easy-to-use interface for composing and sending emails, including support for attachments, templates, and various email options.

What are @sendgrid/mail's main functionalities?

Sending a Simple Email

This feature allows you to send a simple email with a subject, a plain text part, and an HTML part.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'recipient@example.com',
  from: 'sender@example.com',
  subject: 'Sending with SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);

Using Email Templates

This feature allows you to send emails using dynamic templates created on the SendGrid platform. You can pass dynamic data to populate the template.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'recipient@example.com',
  from: 'sender@example.com',
  templateId: 'd-12345678901234567890123456789012',
  dynamicTemplateData: {
    name: 'John',
    city: 'Denver'
  }
};
sgMail.send(msg);

Sending Multiple Emails

This feature allows you to send the same email to multiple recipients with a single API call.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const messages = [
  {
    to: 'recipient1@example.com',
    from: 'sender@example.com',
    subject: 'Hello recipient 1',
    text: 'Sending to multiple recipients is easy!'
  },
  {
    to: 'recipient2@example.com',
    from: 'sender@example.com',
    subject: 'Hello recipient 2',
    text: 'Sending to multiple recipients is easy!'
  }
];
sgMail.send(messages);

Adding Attachments

This feature allows you to send emails with attachments. The attachment content should be base64 encoded.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'recipient@example.com',
  from: 'sender@example.com',
  subject: 'Attachment Example',
  text: 'Please find the attached file.',
  attachments: [
    {
      content: 'Some base64 encoded content',
      filename: 'somefile.txt',
      type: 'plain/text',
      disposition: 'attachment',
      contentId: 'mytext'
    }
  ]
};
sgMail.send(msg);

Other packages similar to @sendgrid/mail

FAQs

Package last updated on 18 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc