Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@sendgrid/client
Advanced tools
The @sendgrid/client npm package is a JavaScript client for interacting with the SendGrid API. It allows developers to easily integrate SendGrid's email sending capabilities into their applications. The package provides a way to send emails, manage contacts, and perform other email-related tasks programmatically.
Sending Emails
This feature allows you to send emails using the SendGrid API. The code sample demonstrates how to send a simple text email.
const sgClient = require('@sendgrid/client');
sgClient.setApiKey(process.env.SENDGRID_API_KEY);
const request = {
method: 'POST',
url: '/v3/mail/send',
body: {
personalizations: [{
to: [{ email: 'recipient@example.com' }],
subject: 'Hello, World!'
}],
from: { email: 'sender@example.com' },
content: [{ type: 'text/plain', value: 'Hello, World!' }]
}
};
sgClient.request(request)
.then(([response, body]) => {
console.log(response.statusCode);
console.log(body);
})
.catch(error => {
console.error(error);
});
Managing Contacts
This feature allows for the management of contacts within SendGrid. The code sample shows how to add a new contact to your SendGrid account.
const sgClient = require('@sendgrid/client');
sgClient.setApiKey(process.env.SENDGRID_API_KEY);
const request = {
method: 'PUT',
url: '/v3/marketing/contacts',
body: {
contacts: [{
email: 'newcontact@example.com',
first_name: 'First',
last_name: 'Last'
}]
}
};
sgClient.request(request)
.then(([response, body]) => {
console.log(response.statusCode);
console.log(body);
})
.catch(error => {
console.error(error);
});
Nodemailer is a module for Node.js applications to allow easy email sending. Unlike @sendgrid/client, which is specific to the SendGrid API, Nodemailer supports multiple transport options (SMTP, SendGrid, Mailgun, etc.). This makes Nodemailer more versatile if you need to switch between email services or configure multiple services.
mailgun-js is a simple Node.js module for interacting with the Mailgun API. Similar to @sendgrid/client, it allows for sending emails, managing contacts, and more, but is focused on the Mailgun service. It's a good alternative if you're using Mailgun instead of SendGrid, offering similar functionality tailored to a different email service provider.
This package is part of a monorepo, please see this README for details.
This client library is used by the other SendGrid service packages to make requests to the Sendgrid v3 Web API. You can also use it independently to make custom requests to the SendGrid v3 Web API and other HTTP APIs.
To be notified when this package is updated, please subscribe to email notifications for releases and breaking changes.
Grab your API Key from the SendGrid UI.
Do not hard code your SendGrid API Key into your code. Instead, use an environment variable or some other secure means of protecting your 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
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/client
You may also use yarn to install.
yarn add @sendgrid/client
Please see USAGE.md for all endpoint examples for the SendGrid v3 Web API.
const client = require('@sendgrid/client');
client.setApiKey(process.env.SENDGRID_API_KEY);
const request = {
method: 'GET',
url: '/v3/api_keys'
};
client.request(request)
.then(([response, body]) => {
console.log(response.statusCode);
console.log(response.body);
})
sgClient.setDefaultHeader('User-Agent', 'Some user agent string');
sgClient.setDefaultRequest('baseUrl', 'https://api.sendgrid.com/');
You can overwrite the promise implementation you want the client to use. Defaults to the ES6 Promise
:
global.Promise = require('bluebird');
All updates to this library are documented in our CHANGELOG and releases. You may also subscribe to email release notifications for releases and breaking changes.
If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.
We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details.
Please see our troubleshooting guide for common library issues.
@sendgrid/client is guided and supported by the SendGrid Developer Experience Team.
@sendgrid/client is maintained and funded by SendGrid, Inc. The names and logos for @sendgrid/client are trademarks of SendGrid, Inc.
[6.1.4] - 2017-09-11 ##
FAQs
Twilio SendGrid NodeJS API client
The npm package @sendgrid/client receives a total of 1,099,211 weekly downloads. As such, @sendgrid/client popularity was classified as popular.
We found that @sendgrid/client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.