【问题标题】:Nodemailer doesn't send emails to outlook.office365 accountsNodemailer 不向 Outlook.office365 帐户发送电子邮件
【发布时间】:2022-03-09 16:26:26
【问题描述】:

我正在尝试从 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)
    },
  );
  
};

【问题讨论】:

  • 您能否提供有关您是否检查过垃圾邮件的信息。请注意,在 office365 邮件中有某些类型的视图,其中显示的邮件已过滤,包括垃圾邮件/自动邮件。
  • 我检查并发送了多次但没有任何结果

标签: node.js nestjs nodemailer


【解决方案1】:

没关系,我找到了解决办法,显然outlook不接受邮件中的html,如果你把html属性改为text,就会发送出去。

【讨论】:

  • 我什至不认为这是真的
  • 显然,我也意识到,在使用 nodemailer 时,如果您发送 type text,则发送电子邮件,但 type html 它失败,所以这个答案可能有一些上下文。
【解决方案2】:

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

此模板可以使用

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

此模板不起作用:

 <body>
    Hello and welcome
 </body>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-09
    • 2016-02-22
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2019-11-05
    • 2020-10-20
    • 1970-01-01
    相关资源
    最近更新 更多