Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
smtpapi
Advanced tools
Readme
This node module allows you to quickly and more easily generate SendGrid X-SMTPAPI headers.
var smtpapi = require('smtpapi');
var header = smtpapi.Header();
header.addTo('you@youremail.com');
header.setUniqueArgs({cow: 'chicken'});
var smtpapi_header_string = header.jsonString();
See this for more information on the available X-SMTPAPI custom handling instructions.
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": {
...
"smtpapi": "0.0.1"
}
}
Install smtpapi-nodejs and its dependencies:
npm install
var smtpapi = require('smtpapi');
var header = new smtpapi.Header();
This gives you back the stringified json formatted X-SMTPAPI header. Use this with your smtp client of choice.
var smtpapi = require('smtpapi');
var header = new smtpapi.Header();
header.jsonString();
var header = new smtpapi.Header();
header.addTo('you@youremail.com');
header.addTo('other@otheremail.com');
var header = new smtpapi.Header();
header.setTos(['you@youremail.com', 'other@otheremail.com');
var header = new smtpapi.Header();
header.addSubstitution('keep', 'secret'); // sub = {keep: ['secret']}
header.addSubstitution('other', ['one', 'two']); // sub = {keep: ['secret'], other: ['one', 'two']}
var header = new smtpapi.Header();
header.setSubstitution({'-charge-': 'This ship is useless.'}); // section = {'-charge-': 'This ship is useless.'}
var header = new smtpapi.Header();
header.addUniqueArg({cow: 'chicken'}); // unique_args = {cow: 'chicken'}
header.addUniqueArg({cat: 'dog'}); // unique_args = {cow: 'chicken', cat: 'dog'}
var header = new smtpapi.Header();
header.setUniqueArgs({cow: 'chicken'}); // unique_args = {cow: 'chicken'}
header.setUniqueArgs({dad: 'proud'}); // unique_args = {dad: 'proud'}
var header = new smtpapi.Header();
header.addCategory('tactics'); // category = ['tactics']
header.addCategory('advanced'); // category = ['tactics', 'advanced']
var header = new smtpapi.Header();
header.setCategories(['snowball-fight', 'tactics']); // category = ['snowball-fight', 'tactics']
var header = new smtpapi.Header();
header.addSection({'-charge-': 'This ship is useless.'}); // section = {'-charge-': 'This ship is useless.'}
var header = new smtpapi.Header();
header.setSections({'-charge-': 'This ship is useless.', '-other': 'Another section here'}); // section = {'-charge-': 'This ship is useless.', '-other': 'Another section here'}
You can add filter settings one at a time.
var header = new smtpapi.Header();
header.addFilter('footer', 'enable', 1);
header.addFilter('footer', 'text/html', '<strong>boo</strong>');
You can set a filter using an object literal.
var header = new smtpapi.Header();
header.setFilters({
'footer': {
'setting': {
'enable': 1,
'text/plain': 'You can haz footers!'
}
}
});
The following example builds the X-SMTPAPI headers and adds them to nodemailer. Nodemailer then sends the email through SendGrid. You can use this same code in your application or optionally you can use sendgrid-nodejs.
var nodemailer = require('nodemailer');
var smtpapi = require('smtpapi');
// Build the smtpapi header
var header = new smtpapi.Header();
header.addTo('you@youremail.com');
header.setUniqueArgs({cow: 'chicken'});
// Add the smtpapi header to the general headers
var headers = { 'x-smtpapi': header.jsonString() };
// Use nodemailer to send the email
var settings = {
host: "smtp.sendgrid.net",
port: parseInt(587, 10),
requiresAuth: true,
auth: {
user: "sendgrid_username",
pass: "sendgrid_password"
}
};
var smtpTransport = nodemailer.createTransport("SMTP", settings);
var mailOptions = {
from: "Fred Foo <foo@blurdybloop.com>",
to: "bar@blurdybloop.com",
subject: "Hello",
text: "Hello world",
html: "<b>Hello world</b>",
headers: headers
}
smtpTransport.sendMail(mailOptions, function(error, response) {
smtpTransport.close();
if (error) {
console.log(error);
} else {
console.log("Message sent: " + response.message);
}
});
git checkout -b my-new-feature
)git commit -am 'Added some feature'
)git push origin my-new-feature
)npm test
```
FAQs
Build SendGrid X-SMTPAPI headers in nodejs.
The npm package smtpapi receives a total of 14,357 weekly downloads. As such, smtpapi popularity was classified as popular.
We found that smtpapi 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.