使用 nodemailer npm 在 Nodejs 中从一个不存在的邮件 ID (noreply@myserver.com) 发送电子邮件

Sending email from a non existing mail id (noreply@myserver.com) in Nodejs using nodemailer npm

下面是用于发送邮件的示例代码。

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
    host: 'smtp.office365.com', 
    port: 587, 
    auth: {
        user: 'me@myserver.com',
        pass: 'mypassword'
    }
});

var mailOptions = {
    from: 'no-reply@myserver.com', //It will work if i give me@myserver.com but i need no-reply@myserver.com in from option.        
    to: 'someuser@gmail.com',
    subject: 'Sending Email using Node.js',
    text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
    if (error) {
     console.log(error);
    } else {
     console.log('Email sent: ' + info.response);
    }
}); 

如果我在 from 选项中使用 no-reply@myserver.com,我会给出以下错误。

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.

一些电子邮件服务器不接受更改 FROM 地址。这与 nodemailer 无关。您需要检查您的电子邮件服务器配置。