簡體   English   中英

使用 nodemailer 和 smtp 發送郵件而無需身份驗證

[英]Using nodemailer and smtp send mail without authentication

下面是我的代碼。 這適用於gmail smtp 服務器 但是當我使用我的辦公室(不需要身份驗證)時,它失敗了

可能是我使用的語法錯誤。

下面是使用 gmail smtp 的代碼:


    var mailOptions = {
        from: 'xxxx@abcd.com',
        to: 'xxxxyy@abcd.com',
        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://xxxx@abcd.com:"+encodeURIComponent('') + "@xxxx.xxxrxx.com:25");

或者

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' }

我的猜測是語法錯誤。 有人可以糾正我嗎

感謝致敬。

創建SMTP 傳輸消息時,您可以從示例代碼中刪除auth選項。

所以它應該如下所示:

  /**
   * 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) => {

      });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM