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