我用的NodeJS nodemail發送郵件,所以我有我想要創建事件錯誤和成功的一部分,當郵件發送使用回調的NodeJS nodemailer創建活動
var util = require('util');
var event = require('events');
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTansport("SMTP", {
service: "GMAIL",
auth: {
user : "[email protected]",
pass : "pass"
}
});
mail.exports = function(from, to, subject ...){
this.from = from;
this.to = to;
this.subject = subject;
....
this.send = function(){
var options = {
from = this.from;
to = this.to;
};
var obj = this.send;
event.Eventemitter.call(obj);
smtpTransport.sendMail(options, function(err, success) {
if(err){
obj.emit('error', err);
}
if(success){
obj.emit('success', success);
}
});
}
};
則調用郵件,而不是服務
var Mail = require('./mail');
var mail = new Mail();
mail.from = "[email protected]";
mail.to = "[email protected]";
...
mail.send(); //the mail is send
郵件被髮送,但我不知道如果郵件發送或不
mail.send()
.on("error", function(err){
console.log("Mail not send");
})
.on("success", function(success){
console.log("Mail send");
});
我弗洛結婚以下政黨成員 http://www.sitepoint.com/nodejs-events-and-eventemitter/
到底在哪要補充的回調?您需要確保在發送電子郵件之前註冊成功和錯誤回調。 –
當我運行mail.send()我不知道郵件是否發送。所以我想在運行smtpTransport.sendMail()時添加事件錯誤和成功。所以當我聽mail.send()的錯誤和成功時,我可以知道郵件是否被髮送 – goten
你是否設法讓這個工作@goten? –