我有一个邮件服务器设置并可以工作(在Linode上使用docker镜像,在Linode上使用dockerized dovecot / postfix)-我可以在我的macbook上从roundcube和邮件客户端发送和接收邮件。
但是使用相同的SMTP服务器和凭据设置nodemailer,我得到:
{ Error: queryA ECONNREFUSED mail.xxxxx.com
at errnoException (dns.js:50:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:238:19)
code: 'EDNS',
errno: 'ECONNREFUSED',
syscall: 'queryA',
hostname: 'mail.xxxxx.com',
command: 'CONN' }
Run Code Online (Sandbox Code Playgroud)
我正在使用来自文档的示例脚本:
"use strict";
const nodemailer = require("nodemailer");
// async..await is not allowed in global scope, must use a wrapper
async function main(){
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
//let account = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "mail.xxxxx.com",
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: "steve@xxxxx.com",
pass: "pppppp"
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Fred Foo " <foo@example.com>', // sender address
to: "steve@zzzzz.com", // list of receivers
subject: "Hello ?", // Subject line
text: "Hello world?", // plain text body
html: "<b>Hello world?</b>" // html body
};
// send mail with defined transport object
let info = await transporter.sendMail(mailOptions)
console.log("Message sent: %s", info.messageId);
// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);
Run Code Online (Sandbox Code Playgroud)
我也收到相同的错误,而没有尝试使用以下方式发送电子邮件:
transporter.verify((err, success) => {
if (err)
console.error(err);
else
console.log('Your config is correct');
});
Run Code Online (Sandbox Code Playgroud)
小智 5
有同样的问题。只需使用早期版本5.0.0。
对于安装特定版本,请使用 npm install package@version
在我们的情况下: npm install nodemailer@4.7.0
归档时间: |
|
查看次数: |
1181 次 |
最近记录: |