1

Im using nodemailer to send emails especially to outlook .

UPDATE:

With below code im getting Error: Message failed error

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: 'user@domain.com',
      pass: 'password'
    },
    tls: { ciphers: 'SSLv3' }
});

// setup email data with unicode symbols
          let mailOptions = {
            from: '"Fred Foo " <foo@blurdybloop.com>', // sender address
            to: 'myemail@companydomain.com', // 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);
          });

Full error trace:

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

phyme
  • 331
  • 2
  • 11
  • 25
  • I guess i solved it from this link :https://stackoverflow.com/questions/25357440/550-5-7-1-client-does-not-have-permissions-to-send-as-this-sender-office365 where my from address and username was not matching... – phyme Aug 24 '17 at 06:50

1 Answers1

2

I had the same problem, and solved it via bring the from field into correspondence with the auth.user field.

i.e. something like the following will work for me.

var nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
    host: 'smtp.office365.com',
    port: 587,
    auth: {
        user: 'test-user@gmail.com',
        pass: 'password'
    },
    tls: { ciphers: 'SSLv3' }
});

let mailOptions = {
    from: 'user-alias <test-user@gmail.com>', // sender address
    to: 'myemail@companydomain.com', // 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);
);

Notice that the two occurence of test-user@gmail.com should be the same.

I think this is because some email server want to make sure that the declared email sender be same as the real email sender.

luochen1990
  • 3,689
  • 1
  • 22
  • 37