I am using the Python library smtplib
to send Email messages with Office365 as the SMTP server. Everything was fine until a few days ago when my From:
header seemed to not be processed. The Python code I am using:
import smtplib
from email.mime.text import MIMEText
def login():
server = smtplib.SMTP(mail.mail_server, mail.mail_port)
server.starttls()
server.login(mail.mail_username, mail.mail_password)
return server
def send(subject, body):
msg = MIMEText(body)
msg["From"] = mail.mail_from
msg["To"] = ", ".join(mail.mail_to)
msg["Subject"] = subject
server = login()
server.sendmail(mail.mail_username, mail.mail_to, msg.as_string())
server.quit()
send("test", "test")
What is strange is that if I log onto Outlook or OWA, I can see my header if I view the sent message details. I sent a test header of From: xxxx <info@...>
However on the recipients inbox message, the header is simply the Office365 User's name and the info address as shown above (From: Name <info@...>
). The xxxx custom header is gone.
What can be causing my header to be dropped?
While it may not be an ideal solution, I ended up setting up a new email account with the name I wanted and used that, instead of trying to force the From:
header.