3

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)
    },
  );
  
};

ElVincitore
  • 355
  • 2
  • 12
  • Can you include information about if you checked spam messages. Notice that in office365 mail there is certain kinds of view where messages are shown filtered including spam/automated messages. – Danizavtz Feb 02 '21 at 19:01
  • I checked and sent multiple times but nothing – ElVincitore Feb 02 '21 at 20:20

2 Answers2

0

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>
James Ikubi
  • 2,552
  • 25
  • 18
-1

It's ok , I found a solution , apparently outlook doesn't accespt html in emails , if you change the html attribute to text , it will be sent .

ElVincitore
  • 355
  • 2
  • 12