Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

v0.1

  • Loading branch information...
commit ca1f7d824af3ddd1e38251838249e474f0de6eb9 1 parent ced558f
andris9 authored
View
16 LICENSE
@@ -0,0 +1,16 @@
+Copyright (c) 2011 Andris Reinman
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
View
90 README.md
@@ -0,0 +1,90 @@
+Nodemailer
+==========
+
+**Nodemailer** is a simple module to send e-mails with Node.JS.
+
+You can use two ways to send an email message: the *EmailMessage* constructor or the shortcut function *send_mail()*.
+The *send_mail()* function takes all the fields of the e-mail message as a function parameter and sends the e-mail immediately.
+*EmailMessage* allows to compose the message object first and send it later with its method *send()*.
+
+Installation
+------------
+
+Usage
+-----
+
+Using *send_mail()*
+
+ var nodemailer = require("nodemailer");
+
+ nodemailer.send_mail({sender: "me@example.com",
+ to:"you@example.com",
+ subject:"Hello!",
+ body:"Hi, how are you doing?"},
+ function(error, success){
+ console.log("Message "+(success?"sent":"failed"));
+ });
+
+Using *EmailMessage*
+
+ var nodemailer = require("nodemailer");
+
+ var mail = nodemailer.EmailMessage({
+ sender: "me@example.com",
+ to:"you@example.com"
+ });
+ mail.subject = "Hello!";
+ mail.body = "Hi, how are you doing?";
+
+ mail.send(function(error, success){
+ console.log("Message "+(success?"sent":"failed"));
+ });
+
+See examples/example.js for complete example.
+
+The callback function gets two parameters - *error* and *success*. If there's an error, then sending failed and you should check where's the problem.
+If there's no error value but *success* is not *true* then the server wasn't able to process the message correctly. Probably there was timeout while processing
+the message etc - in this case you should re-schedule sending this e-mail. If *success* is *true* then the message was sent successfully.
+
+### NB!
+
+Before sending e-mails you need to set up SMTP server parameters.
+
+ nodemailer.SMTP = {
+ host: "smtp.example.com",
+ port: 25,
+ hostname: "myhost.com",
+ use_authentication: false,
+ user: "",
+ pass: ""
+ }
+
+Email Message Fields
+--------------------
+
+The following are the possible fields of an e-mail message:
+
+ - **sender** The e-mail address of the sender. Can be *sender@server.com* or formatted *Sender Name <sender@server.com>*
+ - **to** Comma separated list of recipients e-mail addresses that will appear on the *To:* field
+ - **cc** Comma separated list of recipients e-mail addresses that will appear on the *Cc:* field
+ - **bcc** Comma separated list of recipients e-mail addresses that will appear on the *Bcc:* field
+ - **reply_to** An e-mail address that will appear on the *Reply-To:* field
+ - **subject** The subject of the e-mail
+ - **body** The plaintext version of the message
+ - **html** The HTML version of the message
+ - **attachments** An array of attachment objects. Attachment object consists of two properties - *filename* and *contents*. Property *contents* can either be a String or a Buffer (for binary data).
+
+Issues
+------
+
+### TLS
+
+Node.JS v0.3.x doesn't support changing to a secure channel in the middle of a connection (STARTTLS). So when a server requires authentication and this must be done over TLS it's a problem.
+
+### Charsets
+
+Currently the only allowed charset is UTF-8.
+
+### Attachments
+
+Do not use large attachments as the attachment contents are read into memory and the final message body is combined into a single string.
View
16 certs/cert.pem
@@ -1,16 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICmzCCAgQCCQCaKP4QNhp5sTANBgkqhkiG9w0BAQUFADCBkTELMAkGA1UEBhMC
-RUUxDjAMBgNVBAgTBUhhcmp1MRAwDgYDVQQHEwdUYWxs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ByF
-qC6Os2ZUisaVuCln/rAtLWDkO4WfBIBAmwJAZSJ/9kKqAeRozEfIhdmhr/JPdLc2
-tIRzj07yQpiIM3DmGk4Q+O61asj7Eivz7i6kQEGTjEG/ogYwsVp/7fAX7wJABu6N
-nUnvJH1y42cZHIv5h8etKjCL7yg8D6B0GWJ1VYshwm9mEGWkObPbe/qEQyQco/uH
-6g2SHI2gF80DQZzSaQJBANLFZIb0bdwZUbR3LWInsD5f+6iNAjLNlmyxhRALWlRc
-RZIgyb8FbSQTZmvxAdrmIjem2+G3igwSPWmbNMVlPhg=
------END RSA PRIVATE KEY-----
View
48 examples/example.js
@@ -0,0 +1,48 @@
+
+var mail = require("../lib/mail");
+
+// Set up SMTP server settings
+// NB! Authentication only works if the server doesn't require auth over TLS
+mail.SMTP = {
+ host: "smtp.example.com",
+ port: 25,
+ hostname: "myhost.com",
+ use_authentication: false,
+ user: "",
+ pass: ""
+}
+
+// Message object
+var message = {
+ sender: 'Example Test <test@example.com>',
+ to: '"My Name" <mymail@example.com>',
+ subject: "Nodemailer is unicode friendly ✔",
+
+ body: "Hello to myself!",
+ html:"<p><b>Hello</b> to myself</p>",
+
+ attachments:[
+ {
+ filename: "notes.txt",
+ contents: "Some notes about this e-mail"
+ }
+ ]
+}
+
+// Callback to be run after the sending is completed
+var callback = function(error, success){
+ if(error){
+ console.log("Error occured");
+ console.log(error.message);
+ return;
+ }
+ if(success){
+ console.log("Message sent successfully!");
+ }else{
+ console.log("Message failed, reschedule!");
+ }
+}
+
+// Send the e-mail
+mail.send_mail(message, callback);
+
View
47 index.js
@@ -1,47 +0,0 @@
-
-var mail = require("./mail");
-
-mail.SMTP = {
- host: "smtp.zone.ee",
- port: 25,
- hostname: "node.ee",
- use_authentication: true,
- user: "test@kreata.ee",
- pass: "Kreata123"
-}
-
-var message = {
- sender: "andris r. <andris@tr.ee>",
- to:"Andris Reinman <andris@kreata.ee>, andmekala@hot.ee",
- subject: "Täpitähed lähevad läbi!",
-
- body: "abc öäõü",
- html:"<p><b>tere tere öäõü</b></p>",
-
- attachments:[
- {
- filename: "möirakaru.txt",
- contents: "tere jõgeva!"
- },
- {
- filename: "tabel.csv",
- contents: new Buffer("nodemailer, v0.1, 2011", 'utf-8')
- }
- ]
-}
-
-var callback = function(error, success){
- if(error){
- console.log("Error occured");
- console.log(error.message);
- return;
- }
- if(success){
- console.log("Message sent successfully!");
- }else{
- console.log("Message failed, reschedule!");
- }
-}
-
-mail.send_mail(message, callback);
-
View
26 mail.js → lib/mail.js
@@ -79,6 +79,7 @@ var gencounter = 0;
* - **body** Message body in plain text
* - **html** Message body in HTML format
* - **attachments** an array of attachements of {filename, contents}
+ * filename (mandatory) is a String, contents can be String or Buffer
*
* All the params can be edited/added after defining the object
*
@@ -261,7 +262,8 @@ EmailMessage.prototype.generateBody = function(){
rows.push("Content-Type: text/plain; charset="+this.charset);
rows.push("Content-Transfer-Encoding: quoted-printable");
rows.push("");
- rows.push(mimelib.encodeQuotedPrintable(this.body.trim()).replace(/^\./gm,'..')+"\r\n");
+ // dots in the beginning of the lines will be replaced with double dots
+ rows.push(mimelib.encodeQuotedPrintable(this.body.trim()).replace(/^\./gm,'..'));
rows.push("");
// html
@@ -270,7 +272,7 @@ EmailMessage.prototype.generateBody = function(){
rows.push("Content-Type: text/html; charset="+this.charset);
rows.push("Content-Transfer-Encoding: quoted-printable");
rows.push("");
- rows.push(mimelib.encodeQuotedPrintable(this.html.trim()).replace(/^\./gm,'..')+"\r\n");
+ rows.push(mimelib.encodeQuotedPrintable(this.html.trim()).replace(/^\./gm,'..'));
rows.push("");
}
@@ -415,7 +417,7 @@ EmailMessage.prototype.send = function(callback){
}
commands.push("DATA");
- runCommands();
+ process.nextTick(runCommands);
// performs a waterfall of SMTP commands
function runCommands(){
@@ -424,18 +426,20 @@ EmailMessage.prototype.send = function(callback){
smtp.send(command, function(error, message){
if(!error){
//console.log("Command '"+command+"' sent, response:\n"+message);
- runCommands();
+ process.nextTick(runCommands);
}else{
//console.log("Command '"+command+"' ended with error\n"+error.message);
smtp.close();
- callback && callback(error, null);
+ process.nextTick(function(){
+ callback && callback(error, null);
+ });
}
});
}else
- sendBody();
+ process.nextTick(sendBody);
}
- // Sends e-mail body to the SMTP server and finishes
+ // Sends e-mail body to the SMTP server and finishes up
function sendBody(){
smtp.send(headers+"\r\n\r\n");
smtp.send(body);
@@ -443,11 +447,15 @@ EmailMessage.prototype.send = function(callback){
if(!error){
smtp.send("QUIT", function(error, message){
smtp.close();
- callback(null, true);
+ process.nextTick(function(){
+ callback(null, true);
+ });
});
}else{
smtp.close();
- callback(null, false);
+ process.nextTick(function(){
+ callback(null, false);
+ });
}
});
}
View
8 mime.js → lib/mime.js
@@ -1,11 +1,11 @@
-// see http://github.com/bnoordhuis/node-iconv for more info
try{
+ // see http://github.com/bnoordhuis/node-iconv for more info
var Iconv = require("iconv").Iconv;
}catch(E){
- var errmsg = "\n\nNB!\n - You need to install node-iconv in order to use "+
- "Mailparser!\n - See http://github.com/bnoordhuis/node-iconv\n"
- throw new ReferenceError(errmsg);
+ // convert nothing
+ Iconv = function(){}
+ Iconv.prototype.convert = function(str){return str};
}
/* mime related functions - encoding/decoding etc*/
/* TODO: Only UTF-8 and Latin1 are allowed with encodeQuotedPrintable */
View
0  smtp.js → lib/smtp.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.