Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jshinted code

  • Loading branch information...
commit 441b3ca95974de7b72267720283b43f755b0b548 1 parent 3aa42b1
@andris9 authored
View
12 README.md
@@ -413,7 +413,7 @@ var smtpTransport = nodemailer.createTransport("SMTP",{
```
Actually, if you are authenticatinw with an e-mail address that has a domain name
-like @gmail.com or @yahoo.com etc., then you don't even need to provide the service name,
+like @gmail.com or @yahoo.com etc., then you don't even need to provide the service name,
it is detected automatically.
```javascript
@@ -579,13 +579,13 @@ var mailOptions = {
### Alternative fields
-In addition to text and HTML, any kind of data can be inserted as an alternative content of the main body - for example a word processing document with the same text as in the HTML field. It is the job of the e-mail client to select and show the best fitting alternative to the reader.
+In addition to text and HTML, any kind of data can be inserted as an alternative content of the main body - for example a word processing document with the same text as in the HTML field. It is the job of the e-mail client to select and show the best fitting alternative to the reader.
Attahcment object consists of the following properties:
* **contents** - String or a Buffer contents for the attachment
* **contentType** - optional content type for the attachment, if not set will be set to "application/octet-stream"
- * **contentEncoding** - optional value of how the data is encoded, defaults to "base64"
+ * **contentEncoding** - optional value of how the data is encoded, defaults to "base64"
If `contents` is empty, the alternative will be discarded. Other fields are optional.
@@ -622,8 +622,8 @@ or with formatted name (includes unicode support)
"Ноде Майлер" <foobar@blurdybloop.com>
```
-To, Cc and Bcc fields accept comma separated list of e-mails or an array of
-emails or an array of comma separated list of e-mails - use it as you like.
+To, Cc and Bcc fields accept comma separated list of e-mails or an array of
+emails or an array of comma separated list of e-mails - use it as you like.
Formatting can be mixed.
```
@@ -700,7 +700,7 @@ var mailOptions = {
};
```
-The image linked is fetched and added automatically as an attachment and the url
+The image linked is fetched and added automatically as an attachment and the url
in the HTML is replaced automatically with a proper `cid:` string.
## Return callback
View
26 bin/nodemailer
@@ -52,16 +52,16 @@ if(configFile){
configFile = {}
}
-var transportType = (argv.transport || configFile.transport || process.env.NODEMAILER_TRANSPORT || "").trim(),
- service = argv.service || configFile.service || process.env.NODEMAILER_SERVICE,
- user = argv.user || argv.u || configFile.user || process.env.NODEMAILER_USER,
- pass = argv.pass || argv.p || configFile.pass || process.env.NODEMAILER_PASS,
- host = argv.host || argv.h || configFile.host || process.env.NODEMAILER_HOST,
- port = argv.port || configFile.port || process.env.NODEMAILER_PORT,
- secure = (argv.secure || configFile.secure || process.env.NODEMAILER_SECURE || "").toString().toLowerCase().trim(),
- key = argv.key || argv.k || configFile.key || process.env.NODEMAILER_KEY,
- secret = argv.secret || configFile.secret || process.env.NODEMAILER_SECRET
- token = argv.token || configFile.token || process.env.NODEMAILER_TOKEN;
+var transportType = (argv.transport || configFile.transport || process.env.NODEMAILER_TRANSPORT || "").trim(),
+ service = argv.service || configFile.service || process.env.NODEMAILER_SERVICE,
+ user = argv.user || argv.u || configFile.user || process.env.NODEMAILER_USER,
+ pass = argv.pass || argv.p || configFile.pass || process.env.NODEMAILER_PASS,
+ host = argv.host || argv.h || configFile.host || process.env.NODEMAILER_HOST,
+ port = argv.port || configFile.port || process.env.NODEMAILER_PORT,
+ secure = (argv.secure || configFile.secure || process.env.NODEMAILER_SECURE || "").toString().toLowerCase().trim(),
+ key = argv.key || argv.k || configFile.key || process.env.NODEMAILER_KEY,
+ secret = argv.secret || configFile.secret || process.env.NODEMAILER_SECRET,
+ token = argv.token || configFile.token || process.env.NODEMAILER_TOKEN;
if(!transportType){
transportType = host?"smtp": (key?"ses":"sendmail");
@@ -69,7 +69,7 @@ if(!transportType){
secure = ["false", "null", "0", "undefined"].indexOf(secure)>=0 ? false : !!secure;
-var transportOptions = {debug: !!argv.debug || !!argv.d};
+var transportOptions = {debug: !!argv.debug || !!argv.d};
switch(transportType.toUpperCase().trim()){
case "SMTP":
@@ -104,7 +104,7 @@ var from = argv.from || argv.f || configFile.from || process.env.NODEMAILER_FROM
text = argv.text,
html = argv.html,
headers = argv.headers,
- attachments = (argv.attachment || argv.a || "").toString().trim();
+ attachments = (argv.attachment || argv.a || "").toString().trim();
if(attachments.length){
attachments = attachments.split(",").map(function(a){return {filePath: a.trim()}})
@@ -136,7 +136,7 @@ if(argv.stdin){
}else{
html = stdin;
}
- });
+ });
}else{
sendMessage();
}
View
10 examples/example_alternative.js
@@ -12,14 +12,14 @@ var transport = nodemailer.createTransport("SMTP", {
console.log('SMTP Configured');
// Message object
-var message = {
-
+var message = {
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <nodemailer@disposebox.com>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
@@ -47,7 +47,7 @@ transport.sendMail(message, function(error){
return;
}
console.log('Message sent successfully!');
-
+
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
View
14 examples/example_autoembedding.js
@@ -12,20 +12,20 @@ var transport = nodemailer.createTransport("SMTP", {
console.log('SMTP Configured');
// Message object
-var message = {
-
+var message = {
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <receiver@example.com>',
-
+
// Subject of the message
subject: 'Automatically embedded image', //
-
+
// HTML body with image that will be converted to embedded attachment
html:'<p>Embedded image: <img src="'+__dirname+'/nyan.gif"/></p>',
-
+
forceEmbeddedImages: true
};
@@ -37,7 +37,7 @@ transport.sendMail(message, function(error){
return;
}
console.log('Message sent successfully!');
-
+
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
View
22 examples/example_dkim.js
@@ -13,14 +13,14 @@ transport.useDKIM({
});
// Message object
-var message = {
-
+var message = {
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <receiver@example.com>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
@@ -30,31 +30,31 @@ var message = {
// plaintext body
text: 'Hello to myself!',
-
+
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
-
+
// An array of attachments
attachments:[
-
+
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
-
+
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
-
+
cid: 'note@node' // should be as unique as possible
},
-
+
// File Stream attachment
{
fileName: 'nyan cat ✔.gif',
@@ -72,7 +72,7 @@ transport.sendMail(message, function(error){
return;
}
console.log('Message sent successfully!');
-
+
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
View
18 examples/example_sendmail.js
@@ -7,43 +7,43 @@ console.log('Sendmail Configured');
// Message object
var message = {
-
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <nodemailer@disposebox.com>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
// plaintext body
text: 'Hello to myself!',
-
+
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
-
+
// An array of attachments
attachments:[
-
+
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
-
+
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
-
+
cid: 'note@node' // should be as unique as possible
},
-
+
// File Stream attachment
{
fileName: 'nyan cat ✔.gif',
View
18 examples/example_ses.js
@@ -22,43 +22,43 @@ transport.useDKIM({
// Message object
var message = {
-
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <receiver@example.com>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
// plaintext body
text: 'Hello to myself!',
-
+
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
-
+
// An array of attachments
attachments:[
-
+
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
-
+
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
-
+
cid: 'note@node' // should be as unique as possible
},
-
+
// File Stream attachment
{
fileName: 'nyancat.gif',
View
22 examples/example_smtp.js
@@ -14,14 +14,14 @@ var transport = nodemailer.createTransport("SMTP", {
console.log('SMTP Configured');
// Message object
-var message = {
-
+var message = {
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <nodemailer@disposebox.com>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
@@ -31,31 +31,31 @@ var message = {
// plaintext body
text: 'Hello to myself!',
-
+
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
-
+
// An array of attachments
attachments:[
-
+
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
-
+
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
-
+
cid: 'note@node' // should be as unique as possible
},
-
+
// File Stream attachment
{
fileName: 'nyan cat ✔.gif',
@@ -73,7 +73,7 @@ transport.sendMail(message, function(error){
return;
}
console.log('Message sent successfully!');
-
+
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
View
24 examples/example_xoauth.js
@@ -5,7 +5,7 @@ var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail', // use well known service
auth: {
// Option one - provide pregenerated token
- // XOAuthToken: "R0VUIGh0dHBzOi8vbWFpbC5nb29...."
+ // XOAuthToken: "R0VUIGh0dHBzOi8vbWFpbC5nb29...."
// or alternatively, use built in generator
XOAuthToken: nodemailer.createXOAuthGenerator({
user: "test.nodemailer@gmail.com",
@@ -21,14 +21,14 @@ var transport = nodemailer.createTransport("SMTP", {
console.log('SMTP Configured');
// Message object
-var message = {
-
+var message = {
+
// sender info
from: 'Sender Name <sender@example.com>',
-
+
// Comma separated list of recipients
to: '"Receiver Name" <receiver@example.com>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
@@ -38,31 +38,31 @@ var message = {
// plaintext body
text: 'Hello to myself!',
-
+
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
-
+
// An array of attachments
attachments:[
-
+
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
-
+
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
-
+
cid: 'note@node' // should be as unique as possible
},
-
+
// File Stream attachment
{
fileName: 'nyan cat ✔.gif',
@@ -80,7 +80,7 @@ transport.sendMail(message, function(error){
return;
}
console.log('Message sent successfully!');
-
+
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
View
22 examples/example_xoauth2.js
@@ -17,14 +17,14 @@ var transport = nodemailer.createTransport("SMTP", {
console.log('SMTP Configured');
// Message object
-var message = {
-
+var message = {
+
// sender info
from: 'Andris Reinman <andris@pipedrive.com>',
-
+
// Comma separated list of recipients
to: '"Andris Tahvel" <andris@tahvel.info>',
-
+
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
@@ -34,31 +34,31 @@ var message = {
// plaintext body
text: 'Hello to myself!',
-
+
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
-
+
// An array of attachments
attachments:[
-
+
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
-
+
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
-
+
cid: 'note@node' // should be as unique as possible
},
-
+
// File Stream attachment
{
fileName: 'nyan cat ✔.gif',
@@ -76,7 +76,7 @@ transport.sendMail(message, function(error){
return;
}
console.log('Message sent successfully!');
-
+
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
View
8 lib/engines/sendmail.js
@@ -5,7 +5,7 @@ module.exports = SendmailTransport;
/**
* <p>Generates a Transport object for Sendmail</p>
- *
+ *
* @constructor
* @param {String} [config] path to the sendmail command
*/
@@ -28,7 +28,7 @@ function SendmailTransport(config){
* <p>Spawns a <code>'sendmail -t'</code> command and streams the outgoing
* message to sendmail stdin. Return callback checks if the sendmail process
* ended with 0 (no error) or not.</p>
- *
+ *
* @param {Object} emailMessage MailComposer object
* @param {Function} callback Callback function to run when the sending is completed
*/
@@ -45,8 +45,8 @@ SendmailTransport.prototype.sendMail = function(emailMessage, callback) {
callback(code?new Error(msg):null, {message: msg, messageId: emailMessage._messageId});
}
});
-
+
emailMessage.pipe(sendmail.stdin);
emailMessage.streamMessage();
-
+
};
View
61 lib/engines/ses.js
@@ -1,6 +1,6 @@
/*
* This file is based on the original SES module for Nodemailer by dfellis
- * https://github.com/andris9/Nodemailer/blob/11fb3ef560b87e1c25e8bc15c2179df5647ea6f5/lib/engines/SES.js
+ * https://github.com/andris9/Nodemailer/blob/11fb3ef560b87e1c25e8bc15c2179df5647ea6f5/lib/engines/SES.js
*/
// NB! Amazon SES does not allow unicode filenames on attachments!
@@ -15,41 +15,41 @@ module.exports = SESTransport;
/**
* <p>Generates a Transport object for Amazon SES</p>
- *
+ *
* <p>Possible options can be the following:</p>
- *
+ *
* <ul>
* <li><b>AWSAccessKeyID</b> - AWS access key (required)</li>
* <li><b>AWSSecretKey</b> - AWS secret (required)</li>
* <li><b>ServiceUrl</b> - optional API endpoint URL (defaults to <code>"https://email.us-east-1.amazonaws.com"</code>)
* </ul>
- *
+ *
* @constructor
* @param {Object} options Options object for the SES transport
*/
function SESTransport(options){
this.options = options || {};
-
+
//Set defaults if necessary
this.options.ServiceUrl = this.options.ServiceUrl || "https://email.us-east-1.amazonaws.com";
}
/**
* <p>Compiles a mailcomposer message and forwards it to handler that sends it.</p>
- *
+ *
* @param {Object} emailMessage MailComposer object
* @param {Function} callback Callback function to run when the sending is completed
*/
SESTransport.prototype.sendMail = function(emailMessage, callback) {
-
+
// SES strips this header line by itself
emailMessage.options.keepBcc = true;
-
+
//Check if required config settings set
if(!this.options.AWSAccessKeyID || !this.options.AWSSecretKey) {
return callback(new Error("Missing AWS Credentials"));
}
-
+
this.generateMessage(emailMessage, (function(err, email){
if(err){
return typeof callback == "function" && callback(err);
@@ -60,17 +60,14 @@ SESTransport.prototype.sendMail = function(emailMessage, callback) {
/**
* <p>Compiles and sends the request to SES with e-mail data</p>
- *
+ *
* @param {String} email Compiled raw e-mail as a string
- * @param {Function} callback Callback function to run once the message has been sent
+ * @param {Function} callback Callback function to run once the message has been sent
*/
SESTransport.prototype.handleMessage = function(email, callback) {
var request,
-
date = new Date(),
-
urlparts = urllib.parse(this.options.ServiceUrl),
-
pairs = {
'Action': 'SendRawEmail',
'RawMessage.Data': (new Buffer(email, "utf-8")).toString('base64'),
@@ -79,11 +76,11 @@ SESTransport.prototype.handleMessage = function(email, callback) {
};
if (this.options.AWSSecurityToken) {
- pairs['SecurityToken'] = this.options.AWSSecurityToken;
+ pairs.SecurityToken = this.options.AWSSecurityToken;
}
var params = this.buildKeyValPairs(pairs),
-
+
reqObj = {
host: urlparts.hostname,
path: urlparts.path || "/",
@@ -98,7 +95,7 @@ SESTransport.prototype.handleMessage = function(email, callback) {
"Algorithm=HmacSHA256"].join(",")
}
};
-
+
//Execute the request on the correct protocol
if(urlparts.protocol.substr() == "https:") {
request = https.request(reqObj, this.responseHandler.bind(this, callback));
@@ -110,19 +107,19 @@ SESTransport.prototype.handleMessage = function(email, callback) {
/**
* <p>Handles the response for the HTTP request to SES</p>
- *
+ *
* @param {Function} callback Callback function to run on end (binded)
* @param {Object} response HTTP Response object
*/
SESTransport.prototype.responseHandler = function(callback, response) {
var body = "", match;
response.setEncoding('utf8');
-
+
//Re-assembles response data
response.on('data', function(d) {
body += d.toString();
});
-
+
//Performs error handling and executes callback, if it exists
response.on('end', function(err) {
if(err instanceof Error) {
@@ -146,53 +143,53 @@ SESTransport.prototype.responseHandler = function(callback, response) {
/**
* <p>Compiles the messagecomposer object to a string.</p>
- *
+ *
* <p>It really sucks but I don't know a good way to stream a POST request with
* unknown legth, so the message needs to be fully composed as a string.</p>
- *
+ *
* @param {Object} emailMessage MailComposer object
* @param {Function} callback Callback function to run once the message has been compiled
*/
SESTransport.prototype.generateMessage = function(emailMessage, callback) {
var email = "";
-
+
emailMessage.on("data", function(chunk){
email += (chunk || "").toString("utf-8");
});
-
+
emailMessage.on("end", function(chunk){
email += (chunk || "").toString("utf-8");
callback(null, email);
});
-
+
emailMessage.streamMessage();
};
/**
* <p>Converts an object into a Array with "key=value" values</p>
- *
- * @param {Object} config Object with keys and values
+ *
+ * @param {Object} config Object with keys and values
* @return {Array} Array of key-value pairs
*/
SESTransport.prototype.buildKeyValPairs = function(config){
var keys = Object.keys(config).sort(),
keyValPairs = [],
key, i, len;
-
+
for(i=0, len = keys.length; i < len; i++) {
key = keys[i];
if(key != "ServiceUrl") {
keyValPairs.push((encodeURIComponent(key) + "=" + encodeURIComponent(config[key])));
}
}
-
+
return keyValPairs.join("&");
};
/**
* <p>Uses SHA-256 HMAC with AWS key on date string to generate a signature</p>
- *
+ *
* @param {String} date ISO UTC date string
* @param {String} AWSSecretKey ASW secret key
*/
@@ -204,7 +201,7 @@ SESTransport.prototype.buildSignature = function(date, AWSSecretKey) {
/**
* <p>Generates an UTC string in the format of YYY-MM-DDTHH:MM:SSZ</p>
- *
+ *
* @param {Date} d Date object
* @return {String} Date string
*/
@@ -219,7 +216,7 @@ SESTransport.prototype.ISODateString = function(d){
/**
* <p>Simple padding function. If the number is below 10, add a zero</p>
- *
+ *
* @param {Number} n Number to pad with 0
* @return {String} 0 padded number
*/
View
46 lib/engines/smtp.js
@@ -18,12 +18,12 @@ wellKnownHosts = Object.keys(wellKnownHosts).reduce(function(lowerCaseKeys, curr
/**
* <p>Generates a Transport object for SMTP</p>
- *
+ *
* <p>NB! This is a pool of connections that try to keep themselves alive. The
* connection is not closed to the server once the message is delivered.</p>
- *
+ *
* <p>Possible options can be the following:</p>
- *
+ *
* <ul>
* <li><b>service</b> - a well known service identifier ("Gmail", "Hotmail"
* etc.) for auto-completing host, port and secure connection settings</li>
@@ -36,19 +36,19 @@ wellKnownHosts = Object.keys(wellKnownHosts).reduce(function(lowerCaseKeys, curr
* <li><b>ignoreTLS</b> - ignore server support for STARTTLS</li>
* <li><b>debug</b> - output client and server messages to console</li>
* <li><b>maxConnections</b> - how many connections to keep in the pool</li>
- * </ul>
- *
+ * </ul>
+ *
* @constructor
* @param {Object} [options] SMTP options
*/
function SMTPTransport(options){
-
-
+
+
this.options = options || {};
-
+
this.initOptions();
-
- this.pool = simplesmtp.createClientPool(this.options.port,
+
+ this.pool = simplesmtp.createClientPool(this.options.port,
this.options.host, this.options);
}
@@ -58,7 +58,7 @@ function SMTPTransport(options){
*/
SMTPTransport.prototype.initOptions = function(){
var keys, key, i, len, service;
-
+
// provide support for legacy API
if(this.options.use_authentication === false){
this.options.auth = false;
@@ -72,21 +72,21 @@ SMTPTransport.prototype.initOptions = function(){
this.options.auth.XOAuthToken = this.options.auth.XOAuthToken || this.options.XOAuthToken;
this.options.auth.XOAuth2 = this.options.auth.XOAuth2 || this.options.XOAuth2;
}
-
+
if(this.options.ssl){
this.options.secureConnection = true;
}
-
+
if(this.options.tls === false){
this.options.ignoreTLS = true;
}
-
+
// lets be modest just in case
this.options.maxConnections = this.options.maxConnections || 5;
-
+
// detect service from the e-mail address if host is not provided before falling to localhost
if(!this.options.host && !this.options.port && !this.options.service && this.options.auth && this.options.auth.user){
- this.options.service = wellKnownDomains[(this.options.auth.user || "").toString().split("@").pop().toLowerCase().trim()] || false;
+ this.options.service = wellKnownDomains[(this.options.auth.user || "").toString().split("@").pop().toLowerCase().trim()] || false;
}
// use well known settings if service is defined
@@ -102,26 +102,26 @@ SMTPTransport.prototype.initOptions = function(){
/**
* <p>Forwards the mailcomposer message object to the simplesmpt client pool</p>
- *
+ *
* @param {Object} emailMessage MailComposer object
* @param {Function} callback Callback function to run when the sending is completed
*/
SMTPTransport.prototype.sendMail = function(emailMessage, callback){
// force SMTP encoding
emailMessage.options.escapeSMTP = true;
-
- if(this.options.requiresAuth &&
- (!this.options.auth || !((this.options.auth.user && this.options.auth.pass) || this.options.auth.XOAuth2 || this.options.auth.XOAuthToken))){
- return typeof callback == "function" &&
+
+ if(this.options.requiresAuth &&
+ (!this.options.auth || !((this.options.auth.user && this.options.auth.pass) || this.options.auth.XOAuth2 || this.options.auth.XOAuthToken))){
+ return typeof callback == "function" &&
callback(new Error("Authentication required, invalid details provided"));
}
-
+
this.pool.sendMail(emailMessage, callback);
};
/**
* <p>Closes the client pool</p>
- *
+ *
* @param {Function} callback Callback function to run once the pool is closed
*/
SMTPTransport.prototype.close = function(callback){
View
14 lib/engines/stub.js
@@ -4,14 +4,14 @@ module.exports = StubTransport;
/**
* <p>Generates a stub Transport object for testing purposes</p>
- *
+ *
* @constructor
*/
function StubTransport(){}
/**
* <p>Generates a raw e-mail source and returns it with callback</p>
- *
+ *
* @param {Object} emailMessage MailComposer object
* @param {Function} callback Callback function to run when the e-mail is composed
*/
@@ -21,19 +21,19 @@ StubTransport.prototype.sendMail = function(emailMessage, callback) {
// sendmail strips this header line by itself
emailMessage.options.keepBcc = true;
-
+
emailMessage.on("data", function(data){
- output += (data || "").toString("utf-8");
+ output += (data || "").toString("utf-8");
});
-
+
emailMessage.on("error", function(err){
callback(err);
});
-
+
emailMessage.on("end", function(){
callback(null, {message: output, envelope: emailMessage.getEnvelope(), messageId: emailMessage._messageId});
});
emailMessage.streamMessage();
-
+
};
View
28 lib/helpers.js
@@ -3,22 +3,22 @@ module.exports.stripHTML = stripHTML;
/**
* <p>Converts a HTML stringo into plaintext format that resembles Markdown</p>
- *
+ *
* <p>Only good for simple and valid HTML, probably breaks on eveything else</p>
*
* <p>Placeholders:</p>
- *
+ *
* <ul>
* <li>-\u0000\u0000- for newline</li>
* <li>-\u0001\u0001- for a space</li>
* <li>-\u0002\u0002- temporary newlines</li>
* </ul>
- *
+ *
* @param {String} str HTML string to convert
* @return {String} Plaintext that resembles Markdown
*/
function stripHTML(str){
- str = (str || "").toString("utf-8").trim();
+ str = (str || "").toString("utf-8").trim();
// remove head
str = str.replace(/<head[\s\S]{1,}?\/head>/gi, '');
@@ -35,7 +35,7 @@ function stripHTML(str){
symbol, // line symbol char
len;
- level = Number(level) || 0;
+ level = Number(level) || 0;
content = decodeHTMLEntities(content.replace(/<[^>]*>/g," ").
replace(/\s\s+/g," ")).
@@ -73,7 +73,7 @@ function stripHTML(str){
// ============
return content + "\n" + line + "\n\n";
}
-
+
});
// B
@@ -99,7 +99,7 @@ function stripHTML(str){
// A
str = str.replace(/<a ([^>]*)>(.*?)<\/a[^>]*>/ig,function(match, params, content){
var paramMatch = params.match(/href\s*=\s*['"]([^'"]+)['"]/),
- url = paramMatch && paramMatch[1] || "#";
+ url = paramMatch && paramMatch[1] || "#";
return "[" + content.trim() + "]" + "(" + url +")";
});
@@ -109,7 +109,7 @@ function stripHTML(str){
// LI, indent by 2 spaces + *
str = str.replace(/<li[^>]*>(.*?)<\/?(?:li|ol|ul)[^>]*>/ig,function(match, content){
-
+
content = content.replace(/<[^>]*>/g," ").
replace(/\s\s+/g," ").
trim();
@@ -139,7 +139,7 @@ function stripHTML(str){
content = content.replace(/\-\u0002\u0002\-([ ]*)/g, function(match, spaces){
// keep spaces in the beginning of the lines
spaces = spaces.replace(/ /g, "-\u0001\u0001-");
-
+
return "\n-\u0001\u0001--\u0001\u0001--\u0001\u0001--\u0001\u0001-" + spaces;
});
@@ -160,13 +160,13 @@ function stripHTML(str){
// restore newlines
str = str.replace(/-\u0000\u0000-/g,"\n");
-
+
// remove spaces before and after newlines
str = str.replace(/[ \t]*\n[ \t]*/g,"\n");
-
+
// remove more than 2 newlines in a row
str = str.replace(/\n\n+/g,"\n\n");
-
+
// restore hidden spaces
str = str.replace(/-\u0001\u0001-/g," ");
@@ -178,7 +178,7 @@ function stripHTML(str){
/**
* <p>Decodes any HTML entities in a string into their unicode form</p>
- *
+ *
* @param {String} text text to decode
* @return {String} Decoded text
*/
@@ -217,7 +217,7 @@ function decodeHTMLEntities(text){
sdot:0x22C5,lceil:0x2308,rceil:0x2309,lfloor:0x230A,rfloor:0x230B,lang:0x2329,rang:0x232A,loz:0x25CA,
spades:0x2660,clubs:0x2663,hearts:0x2665,diams:0x2666
};
-
+
return text.replace(/&(.+?);/g, function(str, ent){
return String.fromCharCode(ent[0] !== '#' ? HTMLEntities[ent] : ent[1] === 'x' ? parseInt(ent.substr(2),16) : parseInt(ent.substr(1), 10));
}
View
54 lib/nodemailer.js
@@ -55,11 +55,11 @@ module.exports.Transport = Transport;
module.exports.Nodemailer = Nodemailer;
// Export sendMail function (and the alias send_mail for legacy)
-module.exports.sendMail = module.exports.send_mail = sendMail;
+module.exports.sendMail = module.exports.send_mail = sendMail;
function sendMail(options, callback){
var mailer = new Nodemailer(options);
-
+
mailer.validateSettings(function(err){
if(err){
// report validation error back to the client
@@ -69,7 +69,7 @@ function sendMail(options, callback){
mailer.sendMail(callback);
}
});
-
+
return mailer;
}
@@ -77,7 +77,7 @@ function sendMail(options, callback){
/**
* <p>Generates a Nodemailer object which is the main 'hub' for managing the
* send process</p>
- *
+ *
* @constructor
* @param {Object} options Message options object, see README for the complete list of possible options
*/
@@ -111,27 +111,27 @@ function Nodemailer(options){
/**
* <p>Generates an user agent string for Nodemailer with homepage, version etc.</p>
- *
+ *
* @return {String} user agent string for X-Mailer value
*/
Nodemailer.prototype.generateUserAgentString = function(){
var details = [];
-
+
if(packageData.version){
details.push(packageData.version);
}
-
+
if(X_MAILER_HOMEPAGE){
details.push("+"+X_MAILER_HOMEPAGE);
}
-
+
return X_MAILER_NAME+ (details.length?" ("+details.join("; ")+")":"");
};
/**
* <p>Add support for legacy transport settings by checking for global
* variables SMTP, sendmail and SES</p>
- *
+ *
* @return {Object} {@link Transport} object
*/
Nodemailer.prototype.getGlobalTransport = function(){
@@ -163,7 +163,7 @@ Nodemailer.prototype.getGlobalTransport = function(){
* <p>Doesn't do much currently, if the future should link to transport
* validation methods. For example in case of SES should check that AWS
* keys are set up etc.</p>
- *
+ *
* @param {Function} callback Callback function to run after validation
*/
Nodemailer.prototype.validateSettings = function(callback){
@@ -176,7 +176,7 @@ Nodemailer.prototype.validateSettings = function(callback){
/**
* <p>Send the e-mail message by using data from the original options object
* and selected transport</p>
- *
+ *
* @param {Function} callback Callback function to run when the e-mail has been sent (or it failed)
*/
Nodemailer.prototype.sendMail = function(callback){
@@ -191,16 +191,16 @@ Nodemailer.prototype.sendMail = function(callback){
* e-mail message that can be later streamed to the selected transport</p>
*/
Nodemailer.prototype.generateMailObject = function(){
-
+
// set envelope data, subject etc.
this.setGeneralOptions();
-
+
// set module defined headers (date, message-id, etc.)
this.setModuleHeaders();
-
+
// set user defined headers (if any)
this.setUserHeaders();
-
+
// set alternatives (if any)
this.setAlternatives();
@@ -215,13 +215,13 @@ Nodemailer.prototype.generateMailObject = function(){
Nodemailer.prototype.setGeneralOptions = function(){
// generate plaintext if only HTML exists and generateTextFromHTML is true
- if(!(this.options.text || this.options.body) && (this.options.html) &&
+ if(!(this.options.text || this.options.body) && (this.options.html) &&
this.options.generateTextFromHTML){
this.options.text = helpers.stripHTML(this.options.html);
}
-
+
var acceptedFields = ["from", "sender", "to", "subject", "replyTo", "debug",
- "reply_to", "cc", "bcc", "body", "text", "html",
+ "reply_to", "cc", "bcc", "body", "text", "html",
"envelope", "inReplyTo", "references"],
mailOptions = {},
keys = Object.keys(this.options),
@@ -233,11 +233,11 @@ Nodemailer.prototype.setGeneralOptions = function(){
mailOptions[key] = this.options[key];
}
}
-
+
if(this.options.debug){
console.log(mailOptions);
}
-
+
this.mailcomposer.setMessageOption(mailOptions);
};
@@ -265,17 +265,17 @@ Nodemailer.prototype.setUserHeaders = function(){
*/
Nodemailer.prototype.setModuleHeaders = function(){
var messageId;
-
+
// Mailer name + version
this.mailcomposer.addHeader("X-Mailer", this.generateUserAgentString());
-
+
// Date
if(this.options.date){
- this.mailcomposer.addHeader("Date", this.options.date)
+ this.mailcomposer.addHeader("Date", this.options.date);
}else{
this.mailcomposer.addHeader("Date", new Date().toUTCString());
}
-
+
// Message ID
if(this.options.messageId){
messageId = this.options.messageId;
@@ -287,7 +287,7 @@ Nodemailer.prototype.setModuleHeaders = function(){
this.mailcomposer.addHeader("Message-Id", "<"+messageId+">");
this.mailcomposer._messageId = messageId;
}
-
+
};
/**
@@ -303,7 +303,7 @@ Nodemailer.prototype.setAlternatives = function(){
// convert non array value to an array if needed
this.options.alternatives = [].concat(this.options.alternatives);
-
+
for(var i=0, len=this.options.alternatives.length; i<len; i++){
alternative = this.options.alternatives[i];
this.mailcomposer.addAlternative(alternative);
@@ -323,7 +323,7 @@ Nodemailer.prototype.setAttachments = function(){
// convert non array value to an array if needed
this.options.attachments = [].concat(this.options.attachments);
-
+
for(var i=0, len=this.options.attachments.length; i<len; i++){
attachment = this.options.attachments[i];
attachment.userAgent = attachment.userAgent || this.generateUserAgentString();
View
24 lib/transport.js
@@ -15,21 +15,21 @@ Transport.transports = {
"SES": SESTransport,
"SENDMAIL": SendmailTransport,
"STUB": StubTransport
-}
+};
/**
* <p>Generates a Transport object that can be used to deliver e-mail.</p>
- *
- * <p>All transport objects need to have <code>sendMail</code> property defined
+ *
+ * <p>All transport objects need to have <code>sendMail</code> property defined
* and if needed, also an <code>close</code> method</p>
- *
+ *
* @constructor
* @param {String} type The type of the transport, currently available: SMTP, SES and Sendmail
*/
function Transport(type, options){
this.options = options;
-
+
this.transportType = (type || "").toString().trim().toUpperCase();
this.dkimOptions = false;
@@ -39,13 +39,13 @@ function Transport(type, options){
}else{
this.transport = false;
}
-
+
}
/**
* <p>Forwards the generated mailcomposer object to the selected transport
* object for message delivery</p>
- *
+ *
* @param {Object} emailMessage MailComposer object
* @param {Function} callback Callback function to run when the sending is completed
*/
@@ -53,17 +53,17 @@ Transport.prototype.sendMailWithTransport = function(emailMessage, callback){
if(!this.transport){
return callback(new Error("Invalid transport method defined"));
}
-
+
if(this.dkimOptions){
emailMessage.useDKIM(this.dkimOptions);
}
-
+
this.transport.sendMail(emailMessage, callback);
};
/**
* <p>Sets up DKIM signing for this transport object</p>
- *
+ *
* @param {Object} dkim DKIM options
*/
Transport.prototype.useDKIM = function(dkim){
@@ -73,14 +73,14 @@ Transport.prototype.useDKIM = function(dkim){
/**
* <p>Closes the transport when needed, useful with SMTP (which uses connection
* pool) but not so much with SES or Sendmail</p>
- *
+ *
* @param {Function} Callback function to run when the connection is closed
*/
Transport.prototype.close = function(callback){
if(!this.transport){
return callback(new Error("Invalid transport method defined"));
}
-
+
if(typeof this.transport.close == "function"){
this.transport.close(callback);
}else{
View
88 lib/xoauth.js
@@ -6,66 +6,66 @@ var crypto = require("crypto");
module.exports.XOAuthGenerator = XOAuthGenerator;
function XOAuthGenerator(options){
- this.options = options || {};
+ this.options = options || {};
}
XOAuthGenerator.prototype.generate = function(callback){
- return generateXOAuthStr(this.options, callback);
+ return generateXOAuthStr(this.options, callback);
};
function escapeAndJoin(arr){
- return arr.map(encodeURIComponent).join("&");
+ return arr.map(encodeURIComponent).join("&");
}
function hmacSha1(str, key){
- var hmac = crypto.createHmac("sha1", key);
- hmac.update(str);
- return hmac.digest("base64");
+ var hmac = crypto.createHmac("sha1", key);
+ hmac.update(str);
+ return hmac.digest("base64");
}
function initOAuthParams(options){
- return {
- oauth_consumer_key: options.consumerKey || "anonymous",
- oauth_nonce: options.nonce || "" + Date.now() + Math.round(Math.random()*1000000),
- oauth_signature_method: "HMAC-SHA1",
- oauth_version: "1.0",
- oauth_timestamp: options.timestamp || "" + Math.round(Date.now()/1000)
- };
+ return {
+ oauth_consumer_key: options.consumerKey || "anonymous",
+ oauth_nonce: options.nonce || "" + Date.now() + Math.round(Math.random()*1000000),
+ oauth_signature_method: "HMAC-SHA1",
+ oauth_version: "1.0",
+ oauth_timestamp: options.timestamp || "" + Math.round(Date.now()/1000)
+ };
}
function generateOAuthBaseStr(method, requestUrl, params){
- var reqArr = [method, requestUrl].concat(Object.keys(params).sort().map(function(key){
- return key + "=" + encodeURIComponent(params[key]);
- }).join("&"));
-
- return escapeAndJoin(reqArr);
+ var reqArr = [method, requestUrl].concat(Object.keys(params).sort().map(function(key){
+ return key + "=" + encodeURIComponent(params[key]);
+ }).join("&"));
+
+ return escapeAndJoin(reqArr);
}
function generateXOAuthStr(options, callback){
- options = options || {};
-
- var params = initOAuthParams(options),
- requestUrl = options.requestUrl || "https://mail.google.com/mail/b/" + (options.user || "") + "/smtp/",
- baseStr, signatureKey, paramsStr, returnStr;
-
- if(options.token){
- params.oauth_token = options.token;
- }
-
- baseStr = generateOAuthBaseStr(options.method || "GET", requestUrl, params);
-
- signatureKey = escapeAndJoin([options.consumerSecret || "anonymous", options.tokenSecret]);
- params.oauth_signature = hmacSha1(baseStr, signatureKey);
-
- paramsStr = Object.keys(params).sort().map(function(key){
- return key+"=\""+encodeURIComponent(params[key])+"\"";
- }).join(",");
-
- returnStr = [options.method || "GET", requestUrl, paramsStr].join(" ");
-
- if(typeof callback == "function"){
- callback(null, new Buffer(returnStr, "utf-8").toString("base64"));
- }else{
- return new Buffer(returnStr, "utf-8").toString("base64");
- }
+ options = options || {};
+
+ var params = initOAuthParams(options),
+ requestUrl = options.requestUrl || "https://mail.google.com/mail/b/" + (options.user || "") + "/smtp/",
+ baseStr, signatureKey, paramsStr, returnStr;
+
+ if(options.token){
+ params.oauth_token = options.token;
+ }
+
+ baseStr = generateOAuthBaseStr(options.method || "GET", requestUrl, params);
+
+ signatureKey = escapeAndJoin([options.consumerSecret || "anonymous", options.tokenSecret]);
+ params.oauth_signature = hmacSha1(baseStr, signatureKey);
+
+ paramsStr = Object.keys(params).sort().map(function(key){
+ return key+"=\""+encodeURIComponent(params[key])+"\"";
+ }).join(",");
+
+ returnStr = [options.method || "GET", requestUrl, paramsStr].join(" ");
+
+ if(typeof callback == "function"){
+ callback(null, new Buffer(returnStr, "utf-8").toString("base64"));
+ }else{
+ return new Buffer(returnStr, "utf-8").toString("base64");
+ }
}
View
2  package.json
@@ -36,7 +36,7 @@
"node": ">=0.6"
},
"bin": {
- "nodemailer" : "./bin/nodemailer"
+ "nodemailer" : "./bin/nodemailer"
},
"keywords": ["e-mail", "mime", "email", "mail", "sendmail", "ses"]
}
View
94 test/nodemailer.js
@@ -3,56 +3,56 @@ var testCase = require('nodeunit').testCase,
stripHTML = require("../lib/helpers").stripHTML;
exports["General tests"] = {
-
+
"Create a new Nodemailer object": function(test){
// this is more like a stub here
var mail = new nodemailer.Nodemailer();
test.done();
},
-
+
"stripHTML": function(test){
-
+
var html = "<html><head><title>Title</title><style>h1{color:#fe57a1}</style></head><body><h1>Tere &raquo;</h1><ul><li>Test</li></ul></body></html>",
output = "Tere »\n======\n\n * Test";
-
+
test.equal(stripHTML(html).trim(), output);
test.done();
},
-
+
"generate XOAuthToken": function(test){
- nodemailer.createXOAuthGenerator({
- user: "test.nodemailer@gmail.com",
- consumerKey: "anonymous", // optional
- consumerSecret: "anonymous", // optional
- token: "1/O_HgoO4h2uOUfpus0V--7mygICXrQQ0ZajB3ZH52KqM",
- tokenSecret: "_mUBkIwNPnfQBUIWrJrpXJ0c",
- timestamp: "1332499914",
- nonce: "3595015741981970681"
+ nodemailer.createXOAuthGenerator({
+ user: "test.nodemailer@gmail.com",
+ consumerKey: "anonymous", // optional
+ consumerSecret: "anonymous", // optional
+ token: "1/O_HgoO4h2uOUfpus0V--7mygICXrQQ0ZajB3ZH52KqM",
+ tokenSecret: "_mUBkIwNPnfQBUIWrJrpXJ0c",
+ timestamp: "1332499914",
+ nonce: "3595015741981970681"
}).generate(function(err, token){
- test.equal(token, "R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21haWwvYi90ZXN0Lm5vZGVtYWlsZXJAZ21haWwuY29tL3NtdHAvIG9hdXRoX2NvbnN1bWVyX2tleT0iYW5vbnltb3VzIixvYXV0aF9ub25jZT0iMzU5NTAxNTc0MTk4MTk3MDY4MSIsb2F1dGhfc2lnbmF0dXJlPSJZZkt4QlJHZnRkMUx0bk5LMXM5d25QUjM5UnclM0QiLG9hdXRoX3NpZ25hdHVyZV9tZXRob2Q9IkhNQUMtU0hBMSIsb2F1dGhfdGltZXN0YW1wPSIxMzMyNDk5OTE0IixvYXV0aF90b2tlbj0iMSUyRk9fSGdvTzRoMnVPVWZwdXMwVi0tN215Z0lDWHJRUTBaYWpCM1pINTJLcU0iLG9hdXRoX3ZlcnNpb249IjEuMCI=");
- test.done();
+ test.equal(token, "R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21haWwvYi90ZXN0Lm5vZGVtYWlsZXJAZ21haWwuY29tL3NtdHAvIG9hdXRoX2NvbnN1bWVyX2tleT0iYW5vbnltb3VzIixvYXV0aF9ub25jZT0iMzU5NTAxNTc0MTk4MTk3MDY4MSIsb2F1dGhfc2lnbmF0dXJlPSJZZkt4QlJHZnRkMUx0bk5LMXM5d25QUjM5UnclM0QiLG9hdXRoX3NpZ25hdHVyZV9tZXRob2Q9IkhNQUMtU0hBMSIsb2F1dGhfdGltZXN0YW1wPSIxMzMyNDk5OTE0IixvYXV0aF90b2tlbj0iMSUyRk9fSGdvTzRoMnVPVWZwdXMwVi0tN215Z0lDWHJRUTBaYWpCM1pINTJLcU0iLG9hdXRoX3ZlcnNpb249IjEuMCI=");
+ test.done();
});
-
+
},
-
+
"generate XOAuthToken with defaults": function(test){
- nodemailer.createXOAuthGenerator({
- user: "test.nodemailer@gmail.com",
- token: "1/O_HgoO4h2uOUfpus0V--7mygICXrQQ0ZajB3ZH52KqM",
- tokenSecret: "_mUBkIwNPnfQBUIWrJrpXJ0c",
- timestamp: "1332499914",
- nonce: "3595015741981970681"
+ nodemailer.createXOAuthGenerator({
+ user: "test.nodemailer@gmail.com",
+ token: "1/O_HgoO4h2uOUfpus0V--7mygICXrQQ0ZajB3ZH52KqM",
+ tokenSecret: "_mUBkIwNPnfQBUIWrJrpXJ0c",
+ timestamp: "1332499914",
+ nonce: "3595015741981970681"
}).generate(function(err, token){
- test.equal(token, "R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21haWwvYi90ZXN0Lm5vZGVtYWlsZXJAZ21haWwuY29tL3NtdHAvIG9hdXRoX2NvbnN1bWVyX2tleT0iYW5vbnltb3VzIixvYXV0aF9ub25jZT0iMzU5NTAxNTc0MTk4MTk3MDY4MSIsb2F1dGhfc2lnbmF0dXJlPSJZZkt4QlJHZnRkMUx0bk5LMXM5d25QUjM5UnclM0QiLG9hdXRoX3NpZ25hdHVyZV9tZXRob2Q9IkhNQUMtU0hBMSIsb2F1dGhfdGltZXN0YW1wPSIxMzMyNDk5OTE0IixvYXV0aF90b2tlbj0iMSUyRk9fSGdvTzRoMnVPVWZwdXMwVi0tN215Z0lDWHJRUTBaYWpCM1pINTJLcU0iLG9hdXRoX3ZlcnNpb249IjEuMCI=");
- test.done();
+ test.equal(token, "R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21haWwvYi90ZXN0Lm5vZGVtYWlsZXJAZ21haWwuY29tL3NtdHAvIG9hdXRoX2NvbnN1bWVyX2tleT0iYW5vbnltb3VzIixvYXV0aF9ub25jZT0iMzU5NTAxNTc0MTk4MTk3MDY4MSIsb2F1dGhfc2lnbmF0dXJlPSJZZkt4QlJHZnRkMUx0bk5LMXM5d25QUjM5UnclM0QiLG9hdXRoX3NpZ25hdHVyZV9tZXRob2Q9IkhNQUMtU0hBMSIsb2F1dGhfdGltZXN0YW1wPSIxMzMyNDk5OTE0IixvYXV0aF90b2tlbj0iMSUyRk9fSGdvTzRoMnVPVWZwdXMwVi0tN215Z0lDWHJRUTBaYWpCM1pINTJLcU0iLG9hdXRoX3ZlcnNpb249IjEuMCI=");
+ test.done();
});
-
+
},
-
+
"Use default Message-Id value": function(test){
var transport = nodemailer.createTransport("Stub"),
mailOptions = {};
-
+
transport.sendMail(mailOptions, function(error, response){
test.ifError(error);
var regex = "^Message\\-Id:\\s*<[0-9\.a-fA-F]+@"+nodemailer.X_MAILER_NAME.replace(/([\(\)\\\.\[\]\-\?\:\!\{\}])/g, "\\$1")+">$";
@@ -60,13 +60,13 @@ exports["General tests"] = {
test.done();
})
},
-
+
"Use custom Message-Id value": function(test){
var transport = nodemailer.createTransport("Stub"),
mailOptions = {
messageId: "ABCDEF"
};
-
+
transport.sendMail(mailOptions, function(error, response){
test.ifError(error);
test.ok(response.message.match(/Message\-Id:\s*<ABCDEF>/));
@@ -91,26 +91,26 @@ exports["General tests"] = {
test.done();
})
},
-
+
"Use In-Reply-To": function(test){
var transport = nodemailer.createTransport("Stub"),
mailOptions = {
inReplyTo: "abc"
};
-
+
transport.sendMail(mailOptions, function(error, response){
test.ifError(error);
test.ok(response.message.match(/^In\-Reply\-To:\s*<abc>$/m));
test.done();
})
},
-
+
"Use References": function(test){
var transport = nodemailer.createTransport("Stub"),
mailOptions = {
references: ["abc def <ghi>", "jkl"]
};
-
+
transport.sendMail(mailOptions, function(error, response){
test.ifError(error);
test.ok(response.message.match(/^References:\s*<abc> <def> <ghi> <jkl>$/m));
@@ -137,25 +137,25 @@ exports["General tests"] = {
from: "sender1@tr.ee",
to: "receiver1@tr.ee",
envelope: {
- from: "sender2@tr.ee",
+ from: "sender2@tr.ee",
to: "receiver2@tr.ee",
}
};
-
+
transport.sendMail(mailOptions, function(error, response){
test.ifError(error);
test.deepEqual(response.envelope, {from:'sender2@tr.ee',to: [ 'receiver2@tr.ee' ],stamp: 'Postage paid, Par Avion'})
test.done();
})
},
-
+
"Use default envelope": function(test){
var transport = nodemailer.createTransport("Stub"),
mailOptions = {
from: "sender1@tr.ee",
to: "receiver1@tr.ee"
};
-
+
transport.sendMail(mailOptions, function(error, response){
test.ifError(error);
test.deepEqual(response.envelope, {from:'sender1@tr.ee',to: [ 'receiver1@tr.ee' ],stamp: 'Postage paid, Par Avion'})
@@ -166,15 +166,15 @@ exports["General tests"] = {
exports["Transport close"] = {
"SMTP - Callback in transport.close": function(test){
- var transport = nodemailer.createTransport("SMTP", {});
+ var transport = nodemailer.createTransport("SMTP", {});
transport.close(function(){
test.ok(true);
test.done();
});
},
-
+
"SMTP - No callback in transport.close": function(test){
- var transport = nodemailer.createTransport("SMTP", {});
+ var transport = nodemailer.createTransport("SMTP", {});
transport.close();
process.nextTick(function(){
test.ok(true);
@@ -182,15 +182,15 @@ exports["Transport close"] = {
});
},
"Sendmail - Callback in transport.close": function(test){
- var transport = nodemailer.createTransport("Sendmail", {});
+ var transport = nodemailer.createTransport("Sendmail", {});
transport.close(function(){
test.ok(true);
test.done();
});
},
-
+
"Sendmail - No callback in transport.close": function(test){
- var transport = nodemailer.createTransport("Sendmail", {});
+ var transport = nodemailer.createTransport("Sendmail", {});
transport.close();
process.nextTick(function(){
test.ok(true);
@@ -198,15 +198,15 @@ exports["Transport close"] = {
});
},
"SES - Callback in transport.close": function(test){
- var transport = nodemailer.createTransport("SES", {});
+ var transport = nodemailer.createTransport("SES", {});
transport.close(function(){
test.ok(true);
test.done();
});
},
-
+
"SES - No callback in transport.close": function(test){
- var transport = nodemailer.createTransport("SES", {});
+ var transport = nodemailer.createTransport("SES", {});
transport.close();
process.nextTick(function(){
test.ok(true);
Please sign in to comment.
Something went wrong with that request. Please try again.