Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't setup nodemailer with outlook

I'm using "nodemailer": "^4.6.8" and "nodemailer-smtp-transport": "^2.7.4". I am developing contact form on my site and trying to send form mail over the outlook. From some examples over the internet I tried this code, where [email protected] is my email address:

  const transport = nodemailer.createTransport({
        service: "Hotmail",
        auth: {
            user: "[email protected]",
            pass: "xxxxxxxx"
        }
    });

    var mailOptions = {
        from: '[email protected]', // sender address
        to: '[email protected]', // my mail
        subject: `message subject`, // Subject line
        text: 'plain text', // plain text body
        // html: params.html, // html body
        // attachments: params.attachments
    };

    transport.sendMail(mailOptions, (error, info) => {
        if (error) {
            return console.log('Error while sending mail: ' + error);
        } else {
            console.log('Message sent: %s', info.messageId);
        }
        transport.close(); // shut down the connection pool, no more messages.
    });

But this code gives in console error:

Error while sending mail: Error: Message failed: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:62090000, 17.43559:0000000094000000000000000100000000000000, 20.52176:140FCC84140010100A00FE67, 20.50032:140FCC84841710100B004536, 0.35180:6E060000, 255.23226:0A000055, 255.27962:0A000000, 255.27962:0E000000, 255.31418:80030400, 16.55847:AC000000, 17.43559:0000000068010000000000000200000000000000, 20.52176:140FCC8414001010D5050000, 20.50032:140FCC8484171010DA050000, 0.35180:0A001286, 255.23226:DF050000, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:E9050000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:0A005384, 0.37692:01000100, 0.37948:00000600, 5.33852:00000000534D545000000100, 4.56248:DC040000, 7.40748:010000000000010B32303A48, 7.57132:000000000000000039313A36, 1.63016:32000000, 4.39640:DC040000, 8.45434:00000600ED8A4ABA000000000000000036000000, 5.10786:0000000031352E32302E313232382E3032303A4845315052303830314D42323039313A36646663323235632D353465312D346233312D383138612D3134643735373464633538620000000000, 255.1750:2F060000, 255.31418:40000730, 0.22753:34060000, 255.21817:DC040000, 4.60547:DC040000, 0.21966:0A001780, 4.30158:DC040000 [Hostname=HE1PR0801MB2091.eurprd08.prod.outlook.com]

Have no idea What to do, thanks in advance!

like image 879
Dmitry Malugin Avatar asked Oct 14 '18 08:10

Dmitry Malugin


1 Answers

It turns out that code correct, it was security issue. I can send letter only from my account, not anybody else, so with with mailing options everything works correct:

 let mailOptions = {
        from: '[email protected]', // sender address
        to: '[email protected]', // list of receivers
        subject: `subject`, // Subject line
        text: 'text', // plain text body
        // html: html, // html body
        // attachments: attachments
    };
like image 116
Dmitry Malugin Avatar answered Nov 14 '22 17:11

Dmitry Malugin