当我在我的节点js app中使用nodemailer代码时,我在调用api时显示以下错误。
Error: Invalid login: 538 Error: Must issue a STARTTLS command first
at SMTPConnection._formatError (/var/www/html/nodejs/node_modules/nodemailer/lib/smtp-connection/index.js:591:19)
at SMTPConnection._actionAUTHComplete (/var/www/html/nodejs/node_modules/nodemailer/lib/smtp-connection/index.js:1320:34)
at SMTPConnection._responseActions.push.str (/var/www/html/nodejs/node_modules/nodemailer/lib/smtp-connection/index.js:356:26)
at SMTPConnection._processResponse (/var/www/html/nodejs/node_modules/nodemailer/lib/smtp-connection/index.js:747:20)
at SMTPConnection._onData (/var/www/html/nodejs/node_modules/nodemailer/lib/smtp-connection/index.js:543:14)
at Socket._socket.on.chunk (/var/www/html/nodejs/node_modules/nodemailer/lib/smtp-connection/index.js:495:47)
at Socket.emit (events.js:160:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
at Socket.Readable.push (_stream_readable.js:213:10)
这是我的代码
var mysql=require('mysql');
var express=require('express');
var cors=require('cors');
var nodemailer=require('nodemailer');
const app=express();
var bodyParser=require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended:true
}))
app.use(cors());
const smtp = nodemailer.createTransport({
service:'ethereal',
host: 'smtp.ethereal.email',
port: 587,
secure:false,
ignoreTLS:true,
requireTLS:false,
auth: {
user: 'lu4rummljmr72anl@ethereal.email',
pass: '9SYgdaYyQQPDAPm4CP'
}
});
app.get('/',function(req,res) {
return res.send({error:true,message:'working'});
})
app.get('/sent',function(req,res) {
var mailoptions={
from:'ewe***@***',
to:'sdfs**@****',
subject:'test',
text:'hai'
}
smtp.sendMail(mailoptions,function(err,result) {
if(err) throw err;
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
return res.send('send');
})
})
在google上搜索错误之后我明白了它因为在nodemailer配置中错过了添加服务名称。但是在添加服务名称之后它仍然显示相同的错误。
答案 0 :(得分:0)
创建传输器时,似乎是在SMTP上验证您的身份验证。
每"Error Message"
538 Encryption required for requested authentication mechanism.
我建议您仔细检查服务器的凭据