【问题标题】:SMTP server - send emails without auth / password?SMTP 服务器 - 发送没有身份验证/密码的电子邮件?
【发布时间】:2021-08-13 20:51:05
【问题描述】:

我最近收到了向我的代码添加功能的请求。

我的代码的最终结果是同一文件夹中的一堆.csv 文件。 更新要求我通过电子邮件发送这些文件。 可用且强制的方案是通过 SMTP 进行。

现在我已经阅读了它,并且还检查了#nodeMailer npm 包,但它们都需要登录名和密码,但我的经理说我不需要,没有它可以发送电子邮件。

我有 SMTP 的 IP 地址和发送信件的电子邮件地址。

问题:

  • 如何在不实际登录您的邮件帐户的情况下发送电子邮件?
  • 如果 nodemailer 不是一个选项,我如何将文件作为内容附加到电子邮件?
  • 是否有任何 npm 包,或者您能给我提供解决方案或链接,我可以继续阅读以使这个奇迹发生?

【问题讨论】:

标签: javascript node.js smtp


【解决方案1】:

好的,在检查了一些事情和建议后,我得到了以下信息。如果将来有人遇到同样的问题,我会将其发布为答案。

  • 除非得到贵公司的 smtp 的授权,否则您不能在未经身份验证的情况下发送消息check here
  • 如果您被授权发送电子邮件,但不知何故收到错误,如果您尝试向自己发送电子邮件,第一个可能的错误是 没有连接到 VM 或 apiAddresses 冲突 .我通过我公司的 VPN 解决了这个问题。
  • 修复此问题后,您可能会遇到的下一个错误是 sendmail 错误:自签名证书。为了解决这个问题,我找到了答案here

所以,在这个清单完成后,发送邮件的最终代码应该是这样的:

var transporter = nodemailer.createTransport(smtpTransport({
        host: "", // hostname
        secure: false, // use SSL
        port: , // port for secure SMTP
        tls: {
           rejectUnauthorized: false
        }
    }));

 var mailOptions = {
        from: '', // sender address
        to: '', // list of receivers
        cc: '', // Comma separated list or an array
        subject: 'test upgrde nodemailer subject', // Subject line
        html: '<b>Hello world </b>' // html body
    };

transporter.sendMail(mailOptions, function(error, info){
        if(error){
            console.log("/sendmail error");
            console.log(error);
            res.sendStatus(500);
            return;
        }else{
            console.log("Message sent: " + info.response);
            // if you don't want to use this transport object anymore, uncomment following line
            socketTimeout: 30 * 1000 // 0.5 min: Time of inactivity until the connection is closed
            transporter.close(); // shut down the connection pool, no more messages
            res.sendStatus(200);
        }

        // if you don't want to use this transport object anymore, uncomment following line
        transporter.close(); // shut down the connection pool, no more messages
    });

【讨论】:

    猜你喜欢
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 2011-01-17
    相关资源
    最近更新 更多