我正在使用nodemailer在nodejs中发送电子邮件。我可以发送邮件,但脚本不会终止。我不知道如何关闭连接。
这是代码:
var nodemailer = require('nodemailer');
nodemailer.SMTP = {
host: 'localhost'
}
nodemailer.send_mail(
{
sender: 'me@example.com',
to:'my_gmail_nickname@gmail.com',
subject:'Hello!',
html: 'test',
body:'test'
},
function(error, success){
console.log(error);
console.log(success);
console.log('Message ' + success ? 'sent' : 'failed');
});
答案 0 :(得分:3)
我得到了这样的工作:
var nodemailer = require('nodemailer');
var transport = nodemailer.createTransport("SMTP", {
host: 'localhost',
});
var send_email = function (email_content) {
var mailOptions = {
from: 'me@example.com',
to: 'my_gmail_nickname@gmail.com',
subject: 'Hello!',
html: email_content.content
};
transport.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Message sent: ' + info.message);
transport.close();
}
})
};