2017-08-24 141 views
0

我正在使用nodemailer發送電子郵件,尤其是Outlook。nodemailer無法發送來自nodeJS的郵件

UPDATE:

下面的代碼即時得到錯誤:消息失敗,錯誤

var nodemailer = require('nodemailer'); 

// create reusable transporter object using the default SMTP transport 
let transporter = nodemailer.createTransport({ 
    host: 'smtp.office365.com', 
    port: 587, 
    secureConnection: false, // secure:true for port 465, secure:false for port 587 
    auth: { 
     user: '[email protected]', 
     pass: 'password' 
    }, 
    tls: { ciphers: 'SSLv3' } 
}); 

// setup email data with unicode symbols 
      let mailOptions = { 
      from: '"Fred Foo " <[email protected]>', // sender address 
      to: '[email protected]', // list of receivers 
      subject: 'Hello ✔', // Subject line 
      text: 'Hello world ?', // plain text body 
      html: '<b>Hello world ?</b>' // html body 
      }; 

      transporter.sendMail(mailOptions, (error, info) => { 
      if (error) { 
       return console.log(error); 
      } 
      console.log('Message %s sent: %s', info.messageId, info.response); 
      }); 

完整的錯誤跟蹤:

Error: Message failed: 550 5.7.60 SMTP; Client does not have permissions to send as this sender [SG2PR06MB1725.apcprd06.prod.outlook.com] at SMTPConnection._formatError (/var/www/html/Express/Local-MEAN-dev/node_modules/nodemailer/lib/smtp-connection/index.js:557:19) at SMTPConnection._actionSMTPStream (/var/www/html/Express/Local-MEAN-dev/node_modules/nodemailer/lib/smtp-connection/index.js:1385:34) at SMTPConnection._responseActions.push.str (/var/www/html/Express/Local-MEAN-dev/node_modules/nodemailer/lib/smtp-connection/index.js:907:22) at SMTPConnection._processResponse (/var/www/html/Express/Local-MEAN-dev/node_modules/nodemailer/lib/smtp-connection/index.js:706:20) at SMTPConnection._onData (/var/www/html/Express/Local-MEAN-dev/node_modules/nodemailer/lib/smtp-connection/index.js:509:14) at TLSSocket._socket.on.chunk (/var/www/html/Express/Local-MEAN-dev/node_modules/nodemailer/lib/smtp-connection/index.js:657:51) at emitOne (events.js:96:13) at TLSSocket.emit (events.js:191:7) at readableAddChunk (_stream_readable.js:176:18) at TLSSocket.Readable.push (_stream_readable.js:134:10) at TLSWrap.onread (net.js:563:20) code: 'EMESSAGE', response: '550 5.7.60 SMTP; Client does not have permissions to send as this sender [SG2PR06MB1725.apcprd06.prod.outlook.com]', responseCode: 550, command: 'DATA' }

+0

我想我解決它從這個鏈接:https://stackoverflow.com/questions/25357440/550-5-7-1-client-does-not-have-permissions-to-send-as-this- sender-office365我的地址和用戶名不匹配... – phyme

回答

0

我有同樣的問題,並通過解決它將from字段與auth.user字段對應。

即類似下面的東西將適用於我。

var nodemailer = require('nodemailer'); 

let transporter = nodemailer.createTransport({ 
    host: 'smtp.office365.com', 
    port: 587, 
    auth: { 
     user: '[email protected]', 
     pass: 'password' 
    }, 
    tls: { ciphers: 'SSLv3' } 
}); 

let mailOptions = { 
    from: 'user-alias <[email protected]>', // sender address 
    to: '[email protected]', // list of receivers 
    subject: 'Hello ✔', // Subject line 
    text: 'Hello world ?', // plain text body 
    html: '<b>Hello world ?</b>' // html body 
}; 

transporter.sendMail(mailOptions, (error, info) => { 
    if (error) { 
     return console.log(error); 
    } 
    console.log('Message %s sent: %s', info.messageId, info.response); 
); 

請注意,[email protected]的兩次發生應該是相同的。

我認爲這是因爲某些電子郵件服務器想要確保聲明的電子郵件發件人與真實的電子郵件發件人相同。

相關問題