Skip to content

Latest commit

 

History

History
159 lines (113 loc) · 5.07 KB

TROUBLESHOOTING.md

File metadata and controls

159 lines (113 loc) · 5.07 KB

If you have a non-library SendGrid issue, please contact our support team.

If you can't find a solution below, please open an issue.

Table of Contents

Migrating from v2 to v3

Please review our guide on how to migrate from v2 to v3.

Continue Using v2

Here is the last working version with v2 support.

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.

Add the following to your package.json file:

{
  ...
  "dependencies": {
    ...
    "sendgrid": "1.9.2"
  }
}

Install sendgrid-nodejs and its dependencies:

npm install

Alternative Installation

You can also install sendgrid locally with the following command:

npm install sendgrid@1.9.2

Download:

Click the "Clone or download" green button in GitHub and choose download.

Testing v3 /mail/send Calls Directly

Here are some cURL examples for everyday use cases.

Error Messages

To read the error message returned by SendGrid's API, please see this example.

Versions

We follow the MAJOR.MINOR.PATCH versioning scheme as described by SemVer.org. Therefore, we recommend that you always pin (or vendor) the particular version you are utilizing with your code and never auto-update to the latest version. Especially when there is a MAJOR point release since that is guaranteed to be a breaking change. Changes are documented in the CHANGELOG and releases section.

Environment Variables and Your SendGrid API Key

All of our examples assume you are using environment variables to hold your SendGrid API key.

If you choose to add your SendGrid API key directly (not recommended):

process.env.SENDGRID_API_KEY

becomes

'SENDGRID_API_KEY'

In the first case, SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual SendGrid API Key.

If you're using Kubernetes Secrets and passing the API Keys to the Environment using it, You may find that there is a \n character in the environment variable. You can use the trim function to remove it like this:

process.env.SENDGRID_API_KEY.trim();

Using the Package Manager

We upload this library to npm whenever we make a release. This allows you to use npm for easy installation.

In most cases we recommend you download the latest version of the library, but if you need a different version, please use:

npm install @sendgrid/[package name]@X.X.X

Please check here for a list of package names.

If you are using a package.json file:

{
  ...
  "dependencies": {
    ...
    "@sendgrid/[package name]": "X.X.X"
  }
}

Viewing the Request Body

When debugging or testing, it may be useful to examine the raw request body to compare against the documented format.

You can do this right before you call sgMail.send(msg); like so:

const {
  classes: {
    Mail,
  },
} = require('@sendgrid/helpers');
const mail = Mail.create(data);
const body = mail.toJSON();
console.log(body);

Wrapping Text

You can write blog posts using e-mail with the help of SendGrid API, like so:

sgMail.setApiKey(process.env.SendGrid_API_KEY);
let msg = {
  to: '<your-name>@blogger.com',
  from: '<your-name>@gmail.com',
  subject: title,
  html: html,
};
sgMail.send(msg);

You can also wrap the text in the HTML to make a multi-line blog post:

<div style="white-space: pre-wrap;">
  <code>
    int a = 10;
    int b = 10;
    int d = 10;
  </code>
</div>