emailjs/Readme.md

131 lines
4.0 KiB
Markdown
Raw Normal View History

2011-02-23 21:23:37 +00:00
#v0.1
2011-02-24 23:02:24 +00:00
### emailjs
send emails, html and attachments from node.js to any smtp server
2011-02-23 21:23:37 +00:00
### Installing
2011-02-24 23:02:24 +00:00
npm install emailjs
2011-02-23 21:23:37 +00:00
# FEATURES
2011-02-24 23:02:24 +00:00
- works with SSL and TLS smtp servers (ex: gmail)
- supports smtp authentication (PLAIN, LOGIN, CRAMMD5)
2011-02-23 21:23:37 +00:00
- emails are queued and the queue is sent asynchronously
2011-02-24 23:02:24 +00:00
- supports sending html emails and emails with multiple attachments (MIME)
2011-02-23 21:23:37 +00:00
- works with nodejs 3.8 and above
# REQUIRES
- access to an SMTP Server (ex: gmail)
2011-02-24 23:02:24 +00:00
# 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 with the following keys ('from' and 'to' are required)
// returns a Message object
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)
// should only be called once
html // string representing the html version of the email message
## 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
# EXAMPLE USAGE - text only emails
2011-02-23 21:23:37 +00:00
2011-02-23 22:14:20 +00:00
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
2011-02-24 23:02:24 +00:00
user: "username",
password:"password",
host: "smtp.gmail.com",
ssl: true
});
2011-02-23 21:23:37 +00:00
// send the message and get a callback with an error or details of the message that was sent
2011-02-23 22:14:20 +00:00
server.send({
2011-02-24 23:02:24 +00:00
text: "i hope this works",
from: "you <username@gmail.com>",
to: "someone <someone@gmail.com>, another <another@gmail.com>",
cc: "else <else@gmail.com>",
subject: "testing emailjs"
}, function(err, message) { console.log(err || message); });
2011-02-23 21:23:37 +00:00
2011-02-24 23:02:24 +00:00
# EXAMPLE USAGE - html emails and attachments
2011-02-23 21:23:37 +00:00
2011-02-23 22:14:20 +00:00
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
2011-02-24 23:02:24 +00:00
user: "username",
password:"password",
host: "smtp.gmail.com",
ssl: true
});
var headers = {
text: "i hope this works",
from: "you <username@gmail.com>",
to: "someone <someone@gmail.com>, another <another@gmail.com>",
cc: "else <else@gmail.com>",
subject: "testing emailjs"
};
// create the message
var message = email.message.create(headers);
2011-02-23 21:23:37 +00:00
// attach an alternative html email for those with advanced email clients
message.attach_alternative("i <i>hope</i> this works!");
// attach attachments because you can!
2011-02-24 23:02:24 +00:00
message.attach("path/to/file.zip", "application/zip", "renamed.zip");
2011-02-23 21:23:37 +00:00
// 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 async send individual emails instead of a queue
## Authors
eleith