![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
node-sendgrid
Advanced tools
version: 0.0.4
Copyright (c)2011, by Branko Vukelic branko@herdhound.com
Licensed under MIT license (see LICENSE)
node-sendgrid implements the standard SendGrid SMTP API headers for use with libraries like Nodemailer. It currently does not actually send emails. It is just used to generate the SMTP API headers.
You can find the original API documentation on SendGrid SMTP API documentation page. node-sendgrid tries to follow the official API as close as possible.
This library has not yet been fully tested. File any issues you encounter in issue tracker.
The easiest way to install node-sendgrid is to use npm:
npm install node-sendgrid
It has no external dependencies.
The headers API is implemented through Headers constructor:
var Headers = require('node-sendgrid').Headers;
The constructor takes a single argument which sets up the defaults.
var recipients = ['test1@example.com', 'test2@example.com'];
var headers = new Headers({
to: recipients,
sub: {email: recipients},
category: 'test'
});
You can now add more headers using headers methods (documented further below):
headers.addFilterSetting('clicktrack', 'enable', 1)
All defined headers can be accessed through the headers
property of the
headers object:
console.log(headers.headers);
// Outputs:
// { to: [ 'test1@example.com', 'test2@example.com' ],
// sub: { email: [ 'test1@example.com', 'test2@example.com' ] },
// category: 'test',
// filters: { clicktrack: { settings: [Object] } } }
The headers are prepared for usage as a single SMTP API header by calling the
toString()
method. Here is an example using Nodemailer.
var mailer = require('nodemailer');
mailer.SMTP = config.email.sendgrid;
mailer.send_mail({
to: 'test1@example.com',
sender: 'me@mysite.com',
...
headers: {'X-SMTPAPI': headers.toString()}
}, function(err, sent) {
console.log('Email was ' + (sent && 'sent' || 'not sent');
});
The X-SMTPAPI
header would look like this:
'{"to":["test1@example.com","test2@example.com"],
"sub":{"email":["test1@example.com","test2@example.com"]},
"category":"test","filters":{"clicktrack":{"settings":
{"enable":1}}}}'
As discussed above, default headers are set by passing parameters to the constructor. The parameters are:
<% myPlaceholder %>
. The sub vars are key-value pairs, where the
key corresponds to the name of the placeholder. If value is an array, it
needs to contain the same number of items as the number of recipients.Headers object has a few methods that allows you to fine-tune the headers definition once the object is created using the constructor:
to
header. to
can be a string or an array
of strings containing recipient email addresses.key
-val
sub var pair.args
object. Note that this overrides the default set from in
the constructor.setting
for the filter
to val
.The headers object supports one more method toString()
which returns the
JSON string representation of the headers object.
The list of filters and their settings can be found in the SendGrid documentation.
FAQs
SendGrid SMTP API headers library
The npm package node-sendgrid receives a total of 0 weekly downloads. As such, node-sendgrid popularity was classified as not popular.
We found that node-sendgrid demonstrated a not healthy version release cadence and project activity because the last version was released 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.