NodeJS - 使用 nodemailer-smtp-transport 的 nodemailer

NodeJS - nodemailer using nodemailer-smtp-transport

我在让 nodemailer 与 AuthSMTP (https://www.authsmtp.com/) 一起工作时遇到问题。

var nodemailer = require('nodemailer');
var transOptions = {
    host: 'mail.authsmtp.com',
    port: 25,
    secure: false,
    auth: {
        user: '...',
        pass: '...'
    }
};
var transporter = nodemailer.createTransport(transOptions);
var mainOptions = {
    from: 'whatever@domain.com',
    to: 'something@domain.com',
    subject: 'hello',
    text: 'hello world!'
};
var callback = function(err, info){
    if (err) { throw err }
    console.log('sent');
}
transporter.sendMail(mainOptions, callback);

我从 AuthSMTP 返回的错误是:

"Your program, application or device is trying to use SSL with our service but SSL is not enabled on your account."

我不想启用 SSL,并且我将传输选项对象中的 secure 属性 设置为 false,如文档所述:https://github.com/andris9/nodemailer-smtp-transport#usage .

当我设置 nodemailer 不使用 SSL 时,为什么 AuthSMTP 会说我正在使用 SSL...?

你可以试试这个

var transOptions = {
host: 'mail.authsmtp.com',
port: 25,
secure: false,
ignoreTLS: true
auth: {
    user: '...',
    pass: '...',

}

secure – if true the connection will use TLS when connecting to server. If false (the default) then TLS is used if server supports the STARTTLS extension.

在大多数情况下,如果您连接到端口 465,请将此值设置为 true。对于端口 587 或 25,请将其设置为 false。

ignoreTLS – if this is true and secure is false then TLS is not used even if the server supports STARTTLS extension.

所以,像这样的参数:

secure: false, ignoreTLS: true,

如果你想安全一点,我想只是给你设置邮箱,启动IMAP/SMTP和POP/SMTP服务如下:

并在您的电子邮件设置中添加您的通行证: