Nodemailer 在实时服务器上失败
Nodemailer failing on live server
每当我尝试从本地服务器 运行 发送电子邮件时,它都可以正常工作,但是在生产环境中却失败了。
这是日志文件:
at SMTPConnection._actionAUTHComplete (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1335:34)
at SMTPConnection._responseActions.push.str (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1293:18)
at SMTPConnection._processResponse (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:762:20)
at SMTPConnection._onData (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:558:14)
at TLSSocket._socket.on.chunk (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:709:51)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
code: 'EAUTH',
response:
'535 5.7.3 Authentication unsuccessful [YTOPR0101CA0050.CANPRD01.PROD.OUTLOOK.COM]', responseCode: 535, command: 'AUTH LOGIN' }
{ Error: Invalid login: 535 5.7.3 Authentication unsuccessful [YTXPR0101CA0004.CANPRD01.PROD.OUTLOOK.COM]
at SMTPConnection._formatError (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
at SMTPConnection._actionAUTHComplete (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1335:34)
at SMTPConnection._responseActions.push.str (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1293:18)
at SMTPConnection._processResponse (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:762:20)
at SMTPConnection._onData (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:558:14)
at TLSSocket._socket.on.chunk (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:709:51)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
code: 'EAUTH',
response:
'535 5.7.3 Authentication unsuccessful [YTXPR0101CA0004.CANPRD01.PROD.OUTLOOK.COM]',
responseCode: 535,
command: 'AUTH LOGIN' }
这是 node.js 服务器的代码:
#!/usr/bin/env node
const http = require("http");
const url = require('url');
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'Hotmail',
auth: {
user: 'my email',
pass: 'my password'
},
});
const server = http.createServer(function (req, res) {
//console.log(res.getHeader("Message-Author"));
//Parse the address:
var q = url.parse(req.url, true);
/*The parse method returns an object containing url properties*/
/*The query property returns an object with all the querystring parameters as properties:*/
var qdata = q.query;
/*console.log(qdata.name);
console.log(qdata.email);
console.log(qdata.subject);
console.log(qdata.message);*/
var mailOptions = {
from: 'my email',
to: 'my email',
subject: '['+qdata.name+', '+qdata.email+']'+qdata.subject,
text: '[tag]\n\n'+qdata.message
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
res.writeHead(302, {
'Location': 'url here'
});
res.end();
});
server.listen(80, (err) => {
if ( ! err) {
console.log(`server is listening on 80`)
}
})
我不知道为什么当 运行 在本地时它可以正常连接并发送电子邮件,但是当服务器处于活动状态时告诉我 Authentication unsuccessful
。任何 help/pointers 将不胜感激。
您需要为此连接打开一个端口。
来自 nodemailer 文档:
port – 是要连接的端口(如果 is secure 为 false,则默认为 587,如果为 true,则默认为 465)
试试这个,
const transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com", // hostname
secureConnection: false, // TLS requires secureConnection to be false
port: 587, // port for secure SMTP - TLS
tls: {
ciphers:'SSLv3'
},
auth: {
user: 'yourmail@live.com',
pass: 'password'
}
});
每当我尝试从本地服务器 运行 发送电子邮件时,它都可以正常工作,但是在生产环境中却失败了。
这是日志文件:
at SMTPConnection._actionAUTHComplete (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1335:34)
at SMTPConnection._responseActions.push.str (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1293:18)
at SMTPConnection._processResponse (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:762:20)
at SMTPConnection._onData (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:558:14)
at TLSSocket._socket.on.chunk (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:709:51)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
code: 'EAUTH',
response:
'535 5.7.3 Authentication unsuccessful [YTOPR0101CA0050.CANPRD01.PROD.OUTLOOK.COM]', responseCode: 535, command: 'AUTH LOGIN' }
{ Error: Invalid login: 535 5.7.3 Authentication unsuccessful [YTXPR0101CA0004.CANPRD01.PROD.OUTLOOK.COM]
at SMTPConnection._formatError (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
at SMTPConnection._actionAUTHComplete (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1335:34)
at SMTPConnection._responseActions.push.str (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:1293:18)
at SMTPConnection._processResponse (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:762:20)
at SMTPConnection._onData (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:558:14)
at TLSSocket._socket.on.chunk (/home/7278/mailsender/node_modules/nodemailer/lib/smtp-connection/index.js:709:51)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
code: 'EAUTH',
response:
'535 5.7.3 Authentication unsuccessful [YTXPR0101CA0004.CANPRD01.PROD.OUTLOOK.COM]',
responseCode: 535,
command: 'AUTH LOGIN' }
这是 node.js 服务器的代码:
#!/usr/bin/env node
const http = require("http");
const url = require('url');
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'Hotmail',
auth: {
user: 'my email',
pass: 'my password'
},
});
const server = http.createServer(function (req, res) {
//console.log(res.getHeader("Message-Author"));
//Parse the address:
var q = url.parse(req.url, true);
/*The parse method returns an object containing url properties*/
/*The query property returns an object with all the querystring parameters as properties:*/
var qdata = q.query;
/*console.log(qdata.name);
console.log(qdata.email);
console.log(qdata.subject);
console.log(qdata.message);*/
var mailOptions = {
from: 'my email',
to: 'my email',
subject: '['+qdata.name+', '+qdata.email+']'+qdata.subject,
text: '[tag]\n\n'+qdata.message
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
res.writeHead(302, {
'Location': 'url here'
});
res.end();
});
server.listen(80, (err) => {
if ( ! err) {
console.log(`server is listening on 80`)
}
})
我不知道为什么当 运行 在本地时它可以正常连接并发送电子邮件,但是当服务器处于活动状态时告诉我 Authentication unsuccessful
。任何 help/pointers 将不胜感激。
您需要为此连接打开一个端口。 来自 nodemailer 文档:
port – 是要连接的端口(如果 is secure 为 false,则默认为 587,如果为 true,则默认为 465)
试试这个,
const transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com", // hostname
secureConnection: false, // TLS requires secureConnection to be false
port: 587, // port for secure SMTP - TLS
tls: {
ciphers:'SSLv3'
},
auth: {
user: 'yourmail@live.com',
pass: 'password'
}
});