GithubHelp home page GithubHelp logo

artflakes / emailjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eleith/emailjs

1.0 1.0 0.0 999 KB

html emails and attachments to any smtp server with nodejs

License: Other

JavaScript 100.00%

emailjs's Introduction

#v0.1.8

emailjs

send emails, html and attachments from node.js to any smtp server

Installing

npm install emailjs

FEATURES

  • works with SSL and TLS smtp servers (ex: gmail)
  • supports smtp authentication (PLAIN, LOGIN, CRAMMD5)
  • emails are queued and the queue is sent asynchronously
  • supports sending html emails and emails with multiple attachments (MIME)
  • works with nodejs 3.8 and above

REQUIRES

  • access to an SMTP Server (ex: gmail)
  • mysql-oil for queue persistance

EXAMPLE USAGE - text only emails

	var email 	= require("./path/to/emailjs/email");
	var server 	= email.server.connect({
		user:		"username", 
		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
	server.send({
		text:		"i hope this works", 
		from:		"you <[email protected]>", 
		to:		"someone <[email protected]>, another <[email protected]>",
		cc:		"else <[email protected]>",
		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.gmail.com", 
		ssl:		true
	});

	var headers	= {
		text:		"i hope this works", 
		from:		"you <[email protected]>", 
		to:		"someone <[email protected]>, another <[email protected]>",
		cc:		"else <[email protected]>",
		subject:	"testing emailjs"
	};

	// create the message
	var message = email.message.create(headers);

	// attach an alternative html email for those with advanced email clients
	message.attach_alternative("<html>i <i>hope</i> this works!</html>");

	// attach attachments because you can!
	message.attach("path/to/file.zip", "application/zip", "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

API

email.server.connect(options)

// options is an object with the following keys
options =
{
	username // 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 exists, ssl connection will be made)
	tls		// boolean (if true, 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)
}

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

email.message.create(headers)

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

Message.attach_alternative(html, charset)

// should only be called once

html // string representing the html version of the email message
charset // defaults to utf-8 if not passed

Message.attach(path, mime_type, name)

// can be called multiple times, each creating a new
// attachment on the email itself

path 			// string to where the file is located
mime_type	// string of the file mime type
name			// name to give the file as perceived by the recipient

Authors

eleith

emailjs's People

Contributors

izuzak avatar dvv avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.