allow tls to be an object to customize ciphers, pass through arguments in smtp response

This commit is contained in:
eleith 2014-04-06 23:22:08 -07:00
parent 3f926e1af9
commit 13785dadc2
4 changed files with 509 additions and 556 deletions

View File

@ -1,4 +1,4 @@
# emailjs (v0.3.6) [![Build Status](https://secure.travis-ci.org/eleith/emailjs.png)](http://travis-ci.org/eleith/emailjs)
# emailjs (v0.3.7) [![Build Status](https://secure.travis-ci.org/eleith/emailjs.png)](http://travis-ci.org/eleith/emailjs)
send emails, html and attachments (files, streams and strings) from node.js to any smtp server
@ -12,7 +12,6 @@ send emails, html and attachments (files, streams and strings) from node.js to a
- emails are queued and the queue is sent asynchronously
- supports sending html emails and emails with multiple attachments (MIME)
- attachments can be added as strings, streams or file paths
- works with nodejs 0.3.8 and above
## REQUIRES
- access to an SMTP Server (ex: gmail)
@ -26,7 +25,6 @@ var server = email.server.connect({
password:"password",
host: "smtp.gmail.com",
ssl: true
});
// send the message and get a callback with an error or details of the message that was sent
@ -72,6 +70,35 @@ server.send(message, function(err, message) { console.log(err || message); });
// or you can create a new server connection with 'email.server.connect'
// to asynchronously send individual emails instead of a queue
```
## EXAMPLE USAGE - sending through hotmail/outlook
```javascript
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp-mail.outlook.com",
tls: {ciphers: "SSLv3"}
});
var message = {
text: "i hope this works",
from: "you <username@outlook.com>",
to: "someone <someone@gmail.com>, another <another@gmail.com>",
cc: "else <else@gmail.com>",
subject: "testing emailjs",
attachment:
[
{data:"<html>i <i>hope</i> this works!</html>", alternative:true},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]
};
// send the message and get a callback with an error or details of the message that was sent
server.send(message, function(err, message) { console.log(err || message); });
```
# API
## email.server.connect(options)
@ -83,8 +110,8 @@ server.send(message, function(err, message) { console.log(err || message); });
password // password for logging into smtp
host // smtp host
port // smtp port (if null a standard port number will be used)
ssl // boolean or object {key, ca, cert} (if exists, ssl connection will be made)
tls // boolean (if true, starttls will be initiated)
ssl // boolean or object {key, ca, cert} (if true or object, ssl connection will be made)
tls // boolean or object (if true or object, starttls will be initiated)
timeout // max number of milliseconds to wait for smtp responses (defaults to 5000)
domain // domain to greet smtp with (defaults to os.hostname)
}

View File

@ -1,7 +1,7 @@
{
"name": "emailjs",
"description": "send text/html emails and attachments (files, streams and strings) from node.js to any smtp server",
"version": "0.3.6",
"version": "0.3.7",
"author": "eleith",
"contributors":["izuzak", "Hiverness", "mscdex", "jimmybergman"],
"repository":

View File

@ -19,13 +19,14 @@ var SMTPResponse = function(stream, timeout, onerror)
error = function(err)
{
console.log("uh oh", err);
stream.emit('response', SMTPError('connection encountered an error', SMTPError.ERROR, err));
},
timedout = function(err)
{
stream.emit('response', SMTPError('timedout while connecting to smtp server', SMTPError.TIMEDOUT, err));
},
timedout = function(err)
{
stream.emit('response', SMTPError('timedout while connecting to smtp server', SMTPError.TIMEDOUT, err));
},
watch = function(data)
{
@ -47,26 +48,25 @@ var SMTPResponse = function(stream, timeout, onerror)
stream.emit('response', SMTPError('connection has ended', SMTPError.CONNECTIONENDED, err));
};
this.stop = function(err)
{
stream.removeAllListeners('response');
stream.removeListener('data', watch);
stream.removeListener('end', end);
stream.removeListener('close', close);
stream.removeListener('error', error);
this.stop = function(err) {
stream.removeAllListeners('response');
stream.removeListener('data', watch);
stream.removeListener('end', end);
stream.removeListener('close', close);
stream.removeListener('error', error);
if(err && typeof(onerror) == "function")
onerror(err);
};
if(err && typeof(onerror) == "function")
onerror(err);
};
stream.on('data', watch);
stream.on('end', end);
stream.on('close', close);
stream.on('error', error);
stream.setTimeout(timeout, timedout);
stream.setTimeout(timeout, timedout);
};
exports.monitor = function(stream)
exports.monitor = function(stream, timeout, onerror)
{
return new SMTPResponse(stream);
return new SMTPResponse(stream, timeout, onerror);
};

File diff suppressed because it is too large Load Diff