Im unable to use nodemailer to send emails through office365 using following code:
var transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: '587',
auth: {
user: 'user@domain.com',
pass: 'userpassword',
},
});
I have tried with different flags for nodemailer but nothing works:
secureConnection: false,
port: 587,
tls: {
ciphers:'SSLv3'
I have setup app-password in office 365 and can send email with following pyhton code:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
username = "user@domain.com"
password = "userpassword"
mail_from = "email@email.com"
mail_to = "email@email.com"
mail_subject = "Test Subject"
mail_body = "This is a test message"
mimemsg = MIMEMultipart()
mimemsg['From']=mail_from
mimemsg['To']=mail_to
mimemsg['Subject']=mail_subject
mimemsg.attach(MIMEText(mail_body, 'plain'))
connection = smtplib.SMTP(host='smtp.office365.com', port=587)
connection.starttls()
connection.login(username,password)
connection.send_message(mimemsg)
connection.quit()
You can also use the "Outlook365" service of Nodemailer, which sets up the connection options for you.
let transporter = nodemailer.createTransport({
service: 'Outlook365', // no need to set host or port etc.
auth: {
user: 'account.email@example.com',
pass: 'smtp-password'
}
});