我用node_mailder发送邮件,按照例子的代码,运行之后报“TypeError: Object #<Object> has no method 'send’”错误。有这方面遇到这样问题的朋友麽?怎么解决的?
Node.js版本v0.6.15,node_mailder版本v0.6.4,以下是完整代码:
var email = require("mailer");
email.send({
host : "smtp.gmail.com",
port : "25",
ssl: true,
domain : "smtp.gmail.com",
to : "****[@gmail](/user/gmail).com",
from : "****[@gmail](/user/gmail).com",
subject : "node_mailer test email",
body: "Hello! This is a test of the node_mailer.",
authentication : "login",
username : "****[@gmail](/user/gmail).com",
password : "****"
},
function(err, result){
if(err){ console.log(err); }
});
1 回复
奇怪了,用 Nodemailer 就发送成功了,具体代码是Example里面的:
var nodemailer = require("nodemailer");
// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "userpass"
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Sender Name ✔ <[email protected]>", // sender address
to: "[email protected], [email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
}
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore, uncomment following line
//smtpTransport.close(); // shut down the connection pool, no more messages
});