def send_mail(to, subject, body_text):
SERVER = "smtp.office365.com"
FROM = "myemail@mycompany.com"
# Prepare actual message
msg = EmailMessage()
msg.set_content(body_text, subtype='html')
msg['Subject'] = subject
msg['From'] = FROM
msg['To'] = to
# Send the mail
server = smtplib.SMTP(SERVER, 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("myemail@mycompany.com", "password")
server.send_message(msg)
server.quit()
I have this function for sending emails. This is giving me error -
smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server.
I tried to follow some of the answers here - STARTTLS extension not supported by server and modified my code to remove server.ehlo()
before server.starttls()
but that gives this error -
smtplib.SMTPHeloError: (501, b'5.5.4 Invalid domain name [SN2PR01CA0061.prod.exchangelabs.com]')
Also tried running by removing the line server.starttls()
which gives this error -
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
The send_email
function was working fine up until now when I changed my modem from Xfinity standard rented modem to store bought Netgear Nighthawk C7000. My internet service provider is Xfinity. I don't know if this is an issue but felt like I should mention since this is the only thing that has changed since email sending stopped working.