[英]Error when sending email using nodemailer / smtp.gmail.com
我正在尝试为应用设置nodemailer。 尝试时出现错误。
这是我的设置:
email = setting.email;
password = setting.password;
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: '***********@gmail.com', // real email
pass: '*********' // real password
}});
// var transporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// user: email, // Your email id
// pass: password // Your password
// }
// });
var mailOptions = {// sender address
from: email,
to: to, // list of receivers
subject: sub, // Subject line
text: text, //, /// plaintext body
html: html
}
//console.log(JSON.stringify(mailOptions));
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.error(error);
} else {
console.log(info.response);
}
;
});
});
} catch (error) {
console.error(error);
}
这是我第一次尝试使用nodemailer。 我正在使用真实的电子邮件和密码。 错误是:
(节点:18974)[DEP0025] DeprecationWarning:不建议使用sys。 请改用util。 魔术发生在端口5000 ERROR上! 错误! 错误! 错误! provider_analytic_daily已保存。 {错误:SMTPConnection._onError(/ root / faszz / node_modules / smtp-connection / lib处的SMTPConnection._formatError(/root/faszz/node_modules/smtp-connection/lib/smtp-connection.js:528:15)处的连接超时/smtp-connection.js:514:16)。 (/root/faszz/node_modules/smtp-connection/lib/smtp-connection.js:236:14)在onTimeout(timers.js:498:11)在tryOnTimeout(timers.js:323:5)在Timer.listOnTimeout (timers.js:290:5)代码:“ ETIMEDOUT”,命令:“ CONN”}
functionObj = {};
functionsObj.getSmtpTransport = function() {
var smtpTransport = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "<your email address>",
pass: "<your pass>"
}
});
return smtpTransport;
}
functionsObj.sendMailForPasswordReset = function(to, token) {
var smtpTransport = functionsObj.getSmtpTransport();
var mailOptions = {
to: to,
subject: "Blabla.com Reset Password",
html: "Hi,<br> Click to link for resetting password.<br><a href='https://<blabla.com>/reset/" + urlencode(token) + "'>Click Me !!!</a>"
}
smtpTransport.sendMail(mailOptions, function(error, response) {
if (error) {
return error;
}
else {
return true;
}
});
};
嗨,
上面的代码在我的项目中正常工作,没有任何错误。 但是您应该允许第三方软件使用您从Google来的Google帐户。
在此情况下,Google的支持页面如下:
https://support.google.com/accounts/answer/6010255?hl=en
我建议应该验证所有输入:)例如,如果您要从用户获取“ to”参数。 您应该验证“收件人”参数是否为有效的电子邮件地址?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.