Nodemailer 不会向 outlook.office365 帐户发送电子邮件

Nodemailer doesn't send emails to outlook.office365 accounts

我正在尝试将电子邮件从 gmail 帐户发送到收件人,即我的大学电子邮件 outlook.office365。 它适用于 gmail 到 gmail,gmail 到 outlook.live,gmail 到 yahoo

import * as nodemailer from 'nodemailer';

export const send = async (to, from, subject, html) => {
  // let testAccount = await nodemailer.createTestAccount();
  let transporter = nodemailer.createTransport({
    name: 'Example',
    service: 'gmail',
    secure : false,
    port : 587,
    auth: {
      user: process.env.FROM_EMAIL,
      pass: process.env.PASSWORD,
    },
  });
  transporter.verify(function(error, success) {
    if (error) {
      console.log(error);
    } else {
      console.log("Server is ready to take our messages");
    }
  });
  let info = await transporter.sendMail(
    {
      from,
      to  ,
      subject,
      html,
    },
    (err, info) => {
      if (err) {
        console.log(err);
      }

      console.log(info)
    },
  );
  
};

没关系,我找到了解决方案,显然 outlook 不接受电子邮件中的 html,如果您将 html 属性更改为文本,它将被发送。

对我来说,这是我意识到的,当发送到 office365 时,如果 html 没有 html 标签,则不会发送电子邮件。 即

此模板可以使用

<html>
 <body>
  Hello and welcome
 </body>
</html>

此模板将不起作用:

 <body>
    Hello and welcome
 </body>