8.1.1 • Published 1 month ago

@sendgrid/mail v8.1.1

Weekly downloads
541,300
License
MIT
Repository
github
Last release
1 month ago

BuildStatus npm version

This package is part of a monorepo, please see this README for details.

Mail Service for the SendGrid v3 Web API

This is a dedicated service for interaction with the mail endpoint of the SendGrid v3 API.

Installation

Prerequisites

  • Node.js version 6, 8 or >=10
  • A Twilio SendGrid account, sign up for free to send up to 40,000 emails for the first 30 days or check out our pricing.

Obtain an API Key

Grab your API Key from the Twilio SendGrid UI.

Setup Environment Variables

Do not hardcode your Twilio SendGrid API Key into your code. Instead, use an environment variable or some other secure means of protecting your Twilio SendGrid API Key. Following is an example of using an environment variable.

Update the development environment with your SENDGRID_API_KEY, for example:

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

Install Package

The following recommended installation requires npm. If you are unfamiliar with npm, see the npm docs. Npm comes installed with Node.js since node version 0.8.x, therefore, you likely already have it.

npm install --save @sendgrid/mail

You may also use yarn to install.

yarn add @sendgrid/mail

Verify Sender Identity

Verify an email address or domain in the Sender Authentication tab. Without this you will receive a 403 Forbidden response when trying to send mail.

Quick Start, Hello Email

The following is the minimum needed code to send a simple email. Use this example, and modify the to and from variables:

For more complex use cases, please see USE_CASES.md.

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'test@example.com',
  from: 'test@example.com', // Use the email address or domain you verified above
  subject: 'Sending with Twilio 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>',
};
//ES6
sgMail
  .send(msg)
  .then(() => {}, error => {
    console.error(error);

    if (error.response) {
      console.error(error.response.body)
    }
  });
//ES8
(async () => {
  try {
    await sgMail.send(msg);
  } catch (error) {
    console.error(error);

    if (error.response) {
      console.error(error.response.body)
    }
  }
})();

After executing the above code, you should have an email in the inbox of the recipient. You can check the status of your email in the UI. Alternatively, we can post events to a URL of your choice using our Event Webhook. This gives you data about the events that occur as Twilio SendGrid processes your email.

Troubleshooting

Please see our troubleshooting guide for common library issues.

Announcements

All updates to this library are documented in our CHANGELOG and releases.

How to Contribute

We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details.

About

@sendgrid/mail is maintained and funded by Twilio SendGrid, Inc. The names and logos for @sendgrid/mail are trademarks of Twilio SendGrid, Inc.

If you need help installing or using the library, please check the Twilio SendGrid Support Help Center.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Twilio SendGrid Logo

@argoncs/server@tyz-wallet/tyz-wallet-core-service@falchion-studios/claymore-apidathoang29101997@cinerino/domain@stefancfuchs/firefly-chatbotmern-apiabstractchallengeservernovember2019runcwemailercaoliao-provider-email-sendgridcommie-servicepoint-api-servicemicroservice-emaileditor-serverjailhouse-mail-daemonthinkclear-common-utilrangewell-dataproviderinvoicewave_backquick-parent-uploader@d19n/identityapge-workflownotification-sendernexus-notificationswm-email-v3@community-fibre/identitymd-common-serviceselixir-health-servercollctivlec-multitenant-apitransmetrix-paymentsfcenail-serverswap-apicontrolapp-backendrally-api@mocoin/domain@toei-jp/cinerino-domain@entamecoin/domain@motionpicture/ttts-domainsteezy-api@broadstone/nexus-notificationscress-basecress-utilsmyid-backprebid-adpod-clienttrista_calbitcore-wallet-service-sprclivecore-api@packmate/mail@ploutos/nestjs-email@griddo/public-apiarbitrage-binance-okex-usdtapi.logger2@eucalyptusvc/sendgrid@xmobitea/xmail@apreto/libsgn-server@tealess/provider-email-sendgridtemplate-email-client@gkampitakis/email-client@dometag/utils@project-carbon/serverzipcar_fleet_endpoint@cocs/backend5-htp@pixm/pixm-core-libberserk-provider-email-sendgrid@infinitebrahmanuniverse/nolb-_senbotvoxrharuow-admingcryptonode-multi-mailermembership-system@everything-registry/sub-chunk-821lucabertelli.consulting@hypedevs/reaction-projecte-bundle@hypedevs/reaction-projecte-jobs@xmobitea/gn-serverrr_backend_commonmedusa-plugin-sendgrid-customcg-notifications@futurethemes/galaxy-themekuzzle-plugin-hermes-messengerlifetioncore-wallet-servicelma-sdgridhtb-utilshistory-bot-utilshyinsit-serverkaloraatkastor-depskastor-npmgoodsense-coregroup4-backendgudana-libkudoo-emaillabs-sharableincumqueioc-apiip_emailinfect.orgiis-hub
8.1.1

1 month ago

8.1.0

4 months ago

8.0.0

4 months ago

7.7.0

2 years ago

7.6.2

2 years ago

7.6.1

2 years ago

7.6.0

2 years ago

7.5.0

2 years ago

7.4.7

3 years ago

7.4.6

3 years ago

7.4.5

3 years ago

7.4.4

3 years ago

7.4.2

3 years ago

7.4.1

3 years ago

7.4.0

3 years ago

7.3.0

3 years ago

7.2.6

4 years ago

7.2.5

4 years ago

7.2.4

4 years ago

7.2.3

4 years ago

7.2.2

4 years ago

7.2.1

4 years ago

7.2.0

4 years ago

7.1.1

4 years ago

7.1.0

4 years ago

7.0.1

4 years ago

7.0.0

4 years ago

6.5.5

4 years ago

6.5.4

4 years ago

6.5.3

4 years ago

6.5.2

4 years ago

6.5.1

4 years ago

6.5.0

4 years ago

6.4.0

5 years ago

6.3.1

6 years ago

6.3.0

6 years ago

6.2.1

6 years ago

6.2.0

6 years ago

6.1.4

7 years ago

6.1.3

7 years ago

6.1.2

7 years ago

6.1.1

7 years ago

6.1.0

7 years ago

6.0.0

7 years ago

6.0.0-beta.5

7 years ago

6.0.0-beta.4

7 years ago

6.0.0-beta.3

7 years ago

6.0.0-beta.2

7 years ago

6.0.0-beta.0

7 years ago