Javascript 无法使用NodeEmailer和Node.js发送电子邮件
每当我尝试使用Amazon AWS ec2实例通过NodeEmailer发送电子邮件时,我都会遇到此错误 邮件完全通过localhost发送 错误Javascript 无法使用NodeEmailer和Node.js发送电子邮件,javascript,node.js,nodemailer,Javascript,Node.js,Nodemailer,每当我尝试使用Amazon AWS ec2实例通过NodeEmailer发送电子邮件时,我都会遇到此错误 邮件完全通过localhost发送 错误 { “错误”:{ “代码”:“EAUTH”, “响应”:'534-5.7.14\n'+'534-5.7.14请通过您的web浏览器登录,然后重试。\n'+'534-5.7.14有关详细信息,请访问\n'+'534 5.7.14https://support.google.com/mail/answer/78754 u4sm1382553pjg.55-
{
“错误”:{
“代码”:“EAUTH”,
“响应”:'534-5.7.14\n'+'534-5.7.14请通过您的web浏览器登录,然后重试。\n'+'534-5.7.14有关详细信息,请访问\n'+'534 5.7.14https://support.google.com/mail/answer/78754 u4sm1382553pjg.55-gsmtp',
“响应代码”:534,
“命令”:“普通身份验证”
}
}
我的代码
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
user: 'myproject@gmail.com',
pass: '******'
}
});
var mailOptions = {
// name:'myproject',
from: 'myproject <myproject@gmail.com>',
to: `test@email.com`,
subject: 'myproject',
html`
<html>
<body >
<div style="margin: auto;background-color:#ddd; border: 3px solid #ddd; padding-top:30px;" class="container-step1 container-step2 container-step3 alll width-fix" >
<div style="margin-bottom:15px;margin-left:15px" class="img_responsive_left"><a href=""><img style="height:90px;width:90px" src="${image}" /></a>
</div>
<div style="background-color:white;/*width:100%;*//*width:90%;margin-left:10%;*/padding: 5%" class="all">
<h2 > Dear ${name},</h2>
<p > Thank you for using <b>myproject</b>.<br>
Your OTP for <b>myproject</b> is <b> ${otp} </b> </p>
<p style="/*padding-left:11%;*/margin-bottom: 0px;">
<h3 style="/*margin-left:11%;*/margin-top: 0px;">The <b>myproject</b></h3></p>
</div>
</div>
</div>
</body></html>`,
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
}
else {
console.log('Email sent: ' + info.response);
}
});
var transporter=nodeEmailer.createTransport({
主机:“smtp.gmail.com”,
港口:465,
安全:是的,
服务:“gmail”,
认证:{
用户:'myproject@gmail.com',
通过:“******”
}
});
var mailpoptions={
//名称:'myproject',
来自:“myproject”,
致:`test@email.com`,
主题:“我的项目”,
html`
亲爱的${name},
感谢您使用myproject。
您的myproject的OTP是${OTP}
myproject
`,
};
transporter.sendMail(邮件选项,函数(错误,信息){
如果(错误){
console.log(错误);
}
否则{
console.log('发送的电子邮件:'+信息响应);
}
});
这是一个无效的登录错误,但我的凭证非常好。此错误仅在Amazon AWS中出现
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
user: 'myproject@gmail.com',
pass: '******'
}
});
var mailOptions = {
// name:'myproject',
from: 'myproject <myproject@gmail.com>',
to: `test@email.com`,
subject: 'myproject',
html`
<html>
<body >
<div style="margin: auto;background-color:#ddd; border: 3px solid #ddd; padding-top:30px;" class="container-step1 container-step2 container-step3 alll width-fix" >
<div style="margin-bottom:15px;margin-left:15px" class="img_responsive_left"><a href=""><img style="height:90px;width:90px" src="${image}" /></a>
</div>
<div style="background-color:white;/*width:100%;*//*width:90%;margin-left:10%;*/padding: 5%" class="all">
<h2 > Dear ${name},</h2>
<p > Thank you for using <b>myproject</b>.<br>
Your OTP for <b>myproject</b> is <b> ${otp} </b> </p>
<p style="/*padding-left:11%;*/margin-bottom: 0px;">
<h3 style="/*margin-left:11%;*/margin-top: 0px;">The <b>myproject</b></h3></p>
</div>
</div>
</div>
</body></html>`,
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
}
else {
console.log('Email sent: ' + info.response);
}
});