'Nodemailer doesn't send emails to outlook.office365 accounts

I am trying to send emails from a gmail account to the receiver which is my university email outlook.office365 . it works fine for gmail to gmail , gmail to outlook.live , gmail to 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)
    },
  );
  
};



Solution 1:[1]

For me this was what I realized, when sending to office365, if the html does not have the html tags, then the email is not sent. i.e.

This template will work

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

This template will not work:

 <body>
    Hello and welcome
 </body>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 james ace