我最近收到了向我的代码添加功能的请求。
我的代码的最终结果是同一文件夹中的一堆 .csv
文件。
更新要求我通过电子邮件发送这些文件。
可用和强加的方案是通过 SMTP 来完成。
现在我已经阅读了它,并且还检查了#nodeMailer npm 包,但它们都需要登录名和密码,但我的经理说我不需要登录名和密码,没有它也可以发送电子邮件。
我有 SMTP 的 IP 地址和应该发送信件的电子邮件地址。
问题:
答案 0 :(得分:0)
好的在检查了一些事情和建议后,我得到了以下信息。如果将来有人遇到同样的问题,我会将其发布为答案。
所以,在这个清单完成后,发送邮件的最终代码应该看起来像这样:
var transporter = nodemailer.createTransport(smtpTransport({
host: "", // hostname
secure: false, // use SSL
port: , // port for secure SMTP
tls: {
rejectUnauthorized: false
}
}));
var mailOptions = {
from: '', // sender address
to: '', // list of receivers
cc: '', // Comma separated list or an array
subject: 'test upgrde nodemailer subject', // Subject line
html: '<b>Hello world </b>' // html body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log("/sendmail error");
console.log(error);
res.sendStatus(500);
return;
}else{
console.log("Message sent: " + info.response);
// if you don't want to use this transport object anymore, uncomment following line
socketTimeout: 30 * 1000 // 0.5 min: Time of inactivity until the connection is closed
transporter.close(); // shut down the connection pool, no more messages
res.sendStatus(200);
}
// if you don't want to use this transport object anymore, uncomment following line
transporter.close(); // shut down the connection pool, no more messages
});