nodemailer-mailgun-transport
Advanced tools
Comparing version 1.2.4 to 1.3.4
@@ -5,3 +5,3 @@ { | ||
"description": "A transport module to use with nodemailer to leverage Mailgun's REST API", | ||
"version": "1.2.4", | ||
"version": "1.3.4", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -102,3 +102,16 @@ nodemailer-mailgun-transport | ||
``` | ||
## Address objects | ||
The "from", "to", "cc", and "bcc" fields support an address object or array of address objects. Each "name" and "address" are converted to ```"name <address>"``` format. "name" is optional, "address" is required. Missing or null address in object is skipped. | ||
Examples: | ||
``` | ||
from: {name: 'Sales', address: 'sales@example.com'}, | ||
to: [{name:'Mary', address:'mary@differentexample.com'}, {address:'john@anotherexample.com'}] | ||
``` | ||
is converted to: | ||
``` | ||
from: 'Sales <sales@example.com>', | ||
to: 'Mary <mary@differentexample.com>,john@anotherexample.com' | ||
``` | ||
## Now with Consolidate.js templates | ||
@@ -140,3 +153,3 @@ | ||
npm install nodemailer | ||
npm install git+https://github.com/orliesaurus/nodemailer-mailgun-transport.git | ||
npm install nodemailer-mailgun-transport | ||
``` |
@@ -70,2 +70,32 @@ 'use strict'; | ||
}, | ||
function(done){ | ||
//convert address objects or array of objects to strings if present | ||
var targets =['from','to','cc','bcc']; | ||
var count =0; | ||
for (var target of targets){ | ||
var addrsData = mailData[target]; | ||
if(addrsData !== null && (typeof addrsData === 'object' || Array.isArray(addrsData))){ | ||
var addrs= []; | ||
var addresses = typeof addrsData === 'object' ? [addrsData] : addrsData; | ||
for (var addr of addresses ){ | ||
if (Array.isArray(addr)){ | ||
for (var add of addr){ | ||
if(add.address){ | ||
var final = add.name ? add.name + ' <' + add.address + '>' : add.address | ||
addrs.push(final); | ||
} | ||
} | ||
} else{ | ||
if(addr.address){ | ||
var final = addr.name ? addr.name + ' <' + addr.address + '>' : addr.address | ||
addrs.push(final); | ||
} | ||
} | ||
} | ||
mailData[target] = addrs.join(); | ||
} | ||
count++; | ||
count == 4 ? done():null; | ||
} | ||
}, | ||
function (done) { | ||
@@ -72,0 +102,0 @@ // convert nodemailer attachments to mailgun-js attachements |
@@ -159,2 +159,59 @@ var chai = require('chai'); | ||
}); | ||
}); | ||
describe('with simple address objects', function () { | ||
it('should convert to standard address format', function (done) { | ||
var self = this; | ||
var data = { | ||
from: {"name":'From', "address":'from@bar.com'}, | ||
to: {"name":'To', "address":'to@bar.com'}, | ||
cc: {"name":'Cc', "address":'cc@bar.com'}, | ||
bcc: {"name":'Bcc', "address":'bcc@bar.com'}, | ||
subject: 'Subject', | ||
text: 'Hello', | ||
}; | ||
this.transport.send({ | ||
data: data | ||
}, function () { | ||
expect(self.transport.messages.send).to.have.been.calledWith({ | ||
from: 'From <from@bar.com>', | ||
to: 'To <to@bar.com>', | ||
cc: 'Cc <cc@bar.com>', | ||
bcc: 'Bcc <bcc@bar.com>', | ||
subject: 'Subject', | ||
text: 'Hello' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('with address objects missing data or having multiple entries (array of objects)', function () { | ||
it('should convert to standard address format and skip missing data', function (done) { | ||
var self = this; | ||
var data = { | ||
from: {"name": null, "address":'from@bar.com'}, | ||
to: [{"name":'To', "address":'to@bar.com'}, {"name":null, "address":"to2@bar.com"}, {"address":"to3@bar.com"},{"name":undefined,"address":undefined}], | ||
cc: [{"name":'Cc', "address":'cc@bar.com'}, {"name":null, "address":"cc2@bar.com"}, {"address":"cc3@bar.com"},{"name":"","address":""}], | ||
bcc: [{"name":'Bcc', "address":'bcc@bar.com'}, {"name":null, "address":"bcc2@bar.com"}, {"address":"bcc3@bar.com"},{"name":"Bcc4"}], | ||
subject: 'Subject', | ||
text: 'Hello', | ||
}; | ||
this.transport.send({ | ||
data: data | ||
}, function () { | ||
expect(self.transport.messages.send).to.have.been.calledWith({ | ||
from: 'from@bar.com', | ||
to: 'To <to@bar.com>,to2@bar.com,to3@bar.com', | ||
cc: 'Cc <cc@bar.com>,cc2@bar.com,cc3@bar.com', | ||
bcc: 'Bcc <bcc@bar.com>,bcc2@bar.com,bcc3@bar.com', | ||
subject: 'Subject', | ||
text: 'Hello' | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19265
340
154