使用nodemailer和smtp发送邮件无需身份验证

2024-01-04

下面是我的代码。这适用于Gmail 邮件服务器。 但是当我使用我的办公室(不需要身份验证)时它失败了

可能是我使用的语法是错误的。

下面是使用 gmail smtp 的代码:


    var mailOptions = {
        from: '[email protected] /cdn-cgi/l/email-protection',
        to: '[email protected] /cdn-cgi/l/email-protection',
        subject: 'hello world!',
        html: '<img src="cid:logo">',
        attachments: [{
            filename: 'test.png',
            path: 'D:/bbbbb/mmmm/src/test.png',
            cid: 'logo' //same cid value as in the html img src
        }]
    };

    transport.sendMail(mailOptions, (error, info) => {
        if (error) {
            console.log(error);
        }
        console.log(`Message sent: ${info.response}`);
    }); 

作为我们公司smtp不需要身份验证, 我试过下面的代码:

 var transport = nodemailer.createTransport("smtps://[email protected] /cdn-cgi/l/email-protection:"+encodeURIComponent('') + "@xxxx.xxxrxx.com:25");

OR

var transport = nodemailer.createTransport("smtps://xxx.xxx.com:25");

但一切都导致错误

{ Error: 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:797:

at Error (native) code: 'ECONNECTION', command: 'CONN' }

我的猜测是语法错误。 有人可以纠正我吗

感谢致敬。


您可以删除auth https://github.com/nodemailer/nodemailer/blob/master/lib/smtp-transport/index.js#L56创建时示例代码中的选项SMTP 传输 https://nodemailer.com/smtp/#examples信息。

所以它应该如下所示:

  /**
   * Initialize transport object
   */
  const transporter = nodemailer.createTransport({
    host: "", //Host
    port: , // Port 
    secure: true
  });

    let mailOptions = {
      from: , // sender address
      to: , // list of receivers
      subject: , // Subject line
      text: , // plain text body
      html: // html body
    };

    /**
     * send mail with defined transport object
     */
    transporter.sendMail(mailOptions,
      (error, info) => {

      });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用nodemailer和smtp发送邮件无需身份验证 的相关文章

随机推荐