Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodemailer-mailgun-transport

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodemailer-mailgun-transport - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

.travis.yml

15

package.json

@@ -5,3 +5,3 @@ {

"description": "A transport module to use with nodemailer to leverage Mailgun's REST API",
"version": "1.0.2",
"version": "1.1.0",
"repository": {

@@ -11,2 +11,5 @@ "type": "git",

},
"scripts": {
"test": "mocha"
},
"keywords": [

@@ -35,4 +38,14 @@ "email",

"dependencies": {
"lodash.pickby": "^4.3.0",
"lodash.some": "^4.3.0",
"lodash.startswith": "^4.0.1",
"mailgun-js": "0.7.10"
},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^2.4.5",
"mocha-sinon": "^1.1.5",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0"
}
}

76

src/mailgun-transport.js

@@ -5,3 +5,31 @@ 'use strict';

var packageData = require('../package.json');
var pickBy = require('lodash.pickby');
var some = require('lodash.some');
var startsWith = require('lodash.startswith');
var whitelistExact = [
'from',
'to',
'cc',
'bcc',
'subject',
'text',
'html',
'attachment',
'o:tag',
'o:campaign',
'o:dkim',
'o:deliverytime',
'o:testmode',
'o:tracking',
'o:tracking-clicks',
'o:tracking-opens',
'o:require-tls',
'o:skip-verification'
];
var whitelistPrefix = [
'h:',
'v:'
];
module.exports = function (options) {

@@ -20,2 +48,3 @@ return new MailgunTransport(options);

});
this.messages = this.mailgun.messages();
}

@@ -25,40 +54,29 @@

MailgunTransport.prototype.send = function send(mail, callback) {
var self = this;
var mailData = mail.data;
// convert nodemailer attachments to mailgun-js attachements
if(mailData.attachments){
var a, b, aa = [];
for(var i in mailData.attachments){
a = mailData.attachments[i];
b = new this.mailgun.Attachment({
data : a.path || undefined,
filename : a.filename || undefined,
contentType : a.contentType || undefined,
knownLength : a.knownLength || undefined
if (mailData.attachments) {
mailData.attachment = mailData.attachments.map(function (a) {
return new self.mailgun.Attachment({
data: a.path || undefined,
filename: a.filename || undefined,
contentType: a.contentType || undefined,
knownLength: a.knownLength || undefined
});
});
}
aa.push(b);
var options = pickBy(mailData, function (value, key) {
if (whitelistExact.indexOf(key) !== -1) {
return true;
}
mailData.attachment = aa;
}
var options = {
type : mailData.type,
to : mailData.to,
from : mailData.from,
subject : mailData.subject,
text : mailData.text,
html : mailData.html,
attachment : mailData.attachment
}
if( mailData.bcc ){
options.bcc = mailData.bcc
}
return some(whitelistPrefix, function (prefix) {
return startsWith(key, prefix);
});
});
this.mailgun.messages().send(options, function (err, data) {
this.messages.send(options, function (err, data) {
callback(err || null, data);
});
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc