Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
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 = new smtpapi();
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": "1.0.0"
}
}
Install smtpapi-nodejs and its dependencies:
npm install
var smtpapi = require('smtpapi');
var header = new smtpapi();
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.jsonString();
var header = new smtpapi();
header.addTo('you@youremail.com');
header.addTo('other@otheremail.com');
var header = new smtpapi();
header.setTos(['you@youremail.com', 'other@otheremail.com');
var header = new smtpapi();
header.addSubstitution('keep', ['secret']);
header.addSubstitution('other', ['one', 'two']);
var header = new smtpapi();
header.setSubstitution({'keep': ['secret']);
var header = new smtpapi();
header.addUniqueArg('cat', 'dogs');
var header = new smtpapi();
header.setUniqueArgs({cow: 'chicken'});
header.setUniqueArgs({dad: 'proud'});
var header = new smtpapi();
header.addCategory('tactics');
header.addCategory('advanced');
var header = new smtpapi();
header.setCategories(['tactics', 'advanced']);
var header = new smtpapi();
header.addSection('-charge-', 'This ship is useless.');
var header = new smtpapi();
header.setSections({'-charge-': 'This ship is useless.', '-other': 'Another section here'});
You can add filter settings one at a time.
var header = new smtpapi();
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.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.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.
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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).