Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andris9
committed
Jan 20, 2011
1 parent
e9d4c61
commit ced558f
Showing
4 changed files
with
1,158 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,47 @@ | ||
|
||
var SMTPClient = require("./smtp").SMTPClient; | ||
var mail = require("./mail"); | ||
|
||
|
||
var smtpclient = new SMTPClient("smtp.zone.ee", 25, { | ||
mail.SMTP = { | ||
host: "smtp.zone.ee", | ||
port: 25, | ||
hostname: "node.ee", | ||
use_authentication: true, | ||
user: "test@kreata.ee", | ||
pass: "Kreata123" | ||
}); | ||
|
||
smtpclient.on("error", function(error){ | ||
console.log("Error occured") | ||
console.log(error.message); | ||
}); | ||
|
||
var mail_data = { | ||
from: "andmekala@hot.ee", | ||
to: "andris.reinman@gmail.com", | ||
headers:[ | ||
"From: andmekala@hot.ee", | ||
"To: andris.reinman@gmail.com" | ||
], | ||
subject: "test message", | ||
body: "tere tere\r\nvana kere!" | ||
} | ||
|
||
var commands = []; | ||
commands.push("MAIL FROM:<"+mail_data.from+">"); | ||
commands.push("RCPT TO:<"+mail_data.to+">"); | ||
commands.push("DATA"); | ||
|
||
|
||
function execute(callback){ | ||
var command = commands.shift(); | ||
if(command){ | ||
smtpclient.send(command, function(error, message){ | ||
if(!error){ | ||
//console.log("Command '"+command+"' sent, response:\n"+message); | ||
execute(callback); | ||
}else{ | ||
console.log("Command '"+command+"' ended with error\n"+error.message); | ||
smtpclient.connection.end(); | ||
} | ||
}); | ||
}else | ||
send_body(callback); | ||
} | ||
|
||
function send_body(callback){ | ||
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!", | ||
|
||
var headers = []; | ||
for(var i=0; i<mail_data.headers.length; i++){ | ||
headers.push(mail_data.headers[i]); | ||
} | ||
headers.push("Subject:"+mail_data.subject); | ||
smtpclient.send(headers.join("\r\n")+"\r\n"); | ||
body: "abc öäõü", | ||
html:"<p><b>tere tere öäõü</b></p>", | ||
|
||
smtpclient.send(mail_data.body); | ||
smtpclient.send("\r\n.", function(error, message){ | ||
if(!error){ | ||
console.log("Message sent, response:\n"+message); | ||
smtpclient.send("QUIT", function(error, message){ | ||
smtpclient.close(); | ||
callback(); | ||
}); | ||
|
||
}else{ | ||
console.log("Message ended with error\n"+error.message); | ||
// schedule resend | ||
smtpclient.close(); | ||
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!"); | ||
} | ||
} | ||
|
||
execute(function(){ | ||
console.log("READY!"); | ||
commands.push("MAIL FROM:<"+mail_data.from+">"); | ||
commands.push("RCPT TO:<"+mail_data.to+">"); | ||
commands.push("DATA"); | ||
execute(function(){ | ||
console.log("READY!"); | ||
commands.push("MAIL FROM:<"+mail_data.from+">"); | ||
commands.push("RCPT TO:<"+mail_data.to+">"); | ||
commands.push("DATA"); | ||
execute(function(){ | ||
console.log("TRIPLE READY!") | ||
}) | ||
}) | ||
}); | ||
mail.send_mail(message, callback); | ||
|
Oops, something went wrong.