Go to file
Zack Schuster cb9b6c58bb chore: add yml override to .editorconfig 2020-04-22 19:04:07 -07:00
rollup move rollup files to dedicated folder 2018-08-06 11:57:27 -07:00
smtp move module description to class 2018-07-12 10:03:00 -07:00
test fix typechecking in test/server.js 2018-07-06 13:49:07 -07:00
.editorconfig chore: add yml override to .editorconfig 2020-04-22 19:04:07 -07:00
.eslintrc.json fix whitespace in .eslintrc.json 2018-07-06 13:49:06 -07:00
.gitignore add lockfile 2018-06-21 18:17:33 -07:00
.npmignore update .npmignore 2018-08-06 11:58:34 -07:00
.travis.yml run travis scripts with npm 2018-08-06 12:02:16 -07:00
CHANGELOG.md added changelog, test travis to check node 4 and 5 support 2018-02-11 12:21:21 -08:00
LICENSE updated to MIT license 2011-12-09 02:21:32 -08:00
Readme.md add zackschuster to authors 2018-08-06 11:58:41 -07:00
email.esm.js add & test single-file bundle 2018-07-12 11:44:55 -07:00
email.js move date functions to separate files 2018-06-23 18:33:53 -07:00
package.json move rollup files to dedicated folder 2018-08-06 11:57:27 -07:00
rollup.config.js move rollup files to dedicated folder 2018-08-06 11:57:27 -07:00
yarn.lock add & test single-file bundle 2018-07-12 11:44:55 -07:00

Readme.md

emailjs Build Status

send emails, html and attachments (files, streams and strings) from node.js to any smtp server

INSTALLING

npm install emailjs

FEATURES

  • works with SSL and TLS smtp servers
  • supports smtp authentication ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
  • 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
  • supports utf-8 headers and body

REQUIRES

  • auth access to an SMTP Server
  • if your service (ex: gmail) uses two-step authentication, use an application specific password

EXAMPLE USAGE - text only emails

var email 	= require("./path/to/emailjs/email");
var server 	= email.server.connect({
   user:    "username",
   password:"password",
   host:    "smtp.your-email.com",
   ssl:     true
});

// send the message and get a callback with an error or details of the message that was sent
server.send({
   text:    "i hope this works",
   from:    "you <username@your-email.com>",
   to:      "someone <someone@your-email.com>, another <another@your-email.com>",
   cc:      "else <else@your-email.com>",
   subject: "testing emailjs"
}, function(err, message) { console.log(err || message); });

EXAMPLE USAGE - html emails and attachments

var email 	= require("./path/to/emailjs/email");
var server 	= email.server.connect({
   user:	"username",
   password:"password",
   host:	"smtp.your-email.com",
   ssl:		true
});

var message	= {
   text:	"i hope this works",
   from:	"you <username@your-email.com>",
   to:		"someone <someone@your-email.com>, another <another@your-email.com>",
   cc:		"else <else@your-email.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); });

// you can continue to send more messages with successive calls to 'server.send',
// they will be queued on the same smtp connection

// 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

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@your-email.com>, another <another@your-email.com>",
   cc:		"else <else@your-email.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); });

EXAMPLE USAGE - attaching and embedding an image

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@your-email.com>, another <another@your-email.com>",
   cc:		"else <else@your-email.com>",
   subject:	"testing emailjs",
   attachment:
   [
      {data: "<html>i <i>hope</i> this works! here is an image: <img src='cid:my-image' width='100' height ='50'> </html>"},
      {path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"},
      {path:"path/to/image.jpg", type:"image/jpg", headers:{"Content-ID":"<my-image>"}}
   ]
};

// 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)

// options is an object with the following keys
options =
{
	user 		// username for logging into smtp
	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 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)
authentication // array of preferred authentication methods ('PLAIN', 'LOGIN', 'CRAM-MD5', 'XOAUTH2')
	logger // override the built-in logger (useful for e.g. Azure Function Apps, where console.log doesn't work)
}

email.server.send(message, callback)

// message can be a smtp.Message (as returned by email.message.create)
// or an object identical to the first argument accepted by email.message.create

// callback will be executed with (err, message)
// either when message is sent or an error has occurred

message

// headers is an object ('from' and 'to' are required)
// returns a Message object

// you can actually pass more message headers than listed, the below are just the
// most common ones you would want to use

headers =
{
	text		// text of the email
	from		// sender of the format (address or name <address> or "name" <address>)
	to			// recipients (same format as above), multiple recipients are separated by a comma
	cc			// carbon copied recipients (same format as above)
	bcc		// blind carbon copied recipients (same format as above)
	subject	// string subject of the email
  attachment // one attachment or array of attachments
}

email.SMTP.authentication

associative array of currently supported SMTP authentication mechanisms

attachment

// can be called multiple times, each adding a new attachment
// options is an object with the following possible keys:

options =
{
    // one of these fields is required
    path      // string to where the file is located
    data      // string of the data you want to attach
    stream    // binary stream that will provide attachment data (make sure it is in the paused state)
              // better performance for binary streams is achieved if buffer.length % (76*6) == 0
              // current max size of buffer must be no larger than Message.BUFFERSIZE

    // optionally these fields are also accepted
    type	      // string of the file mime type
    name        // name to give the file as perceived by the recipient
    charset     // charset to encode attatchment in
    method      // method to send attachment as (used by calendar invites)
    alternative // if true, will be attached inline as an alternative (also defaults type='text/html')
    inline      // if true, will be attached inline
    encoded     // set this to true if the data is already base64 encoded, (avoid this if possible)
    headers     // object containing header=>value pairs for inclusion in this attachment's header
    related     // an array of attachments that you want to be related to the parent attachment
}

Authors

eleith zackschuster

Testing

npm install -d
npm test

Contributions

issues and pull requests are welcome