phyme
phyme

Reputation: 351

nodemailer unable to send mails from nodeJS

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: '[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);
          });

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

Upvotes: 1

Views: 3917

Answers (1)

luochen1990
luochen1990

Reputation: 3847

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: '[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);
);

Notice that the two occurence of [email protected] 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.

Upvotes: 2

Related Questions