I'm using python's smtplip for sending emials. Everything id working fine except when I'm use non-ASCI character in message from address.
I'm using python 3.5.
This works fine even with non-ASCI To and Subject:
import smtplib
from email.message import EmailMessage
from email.headerregistry import Addressmsg = EmailMessage()
msg['Subject'] = "Subject with non-asci chars like á"
msg['From'] = Address("Foo Bar", "foo.bar", "example.cz")
msg['To'] = (Address("Fóó Bár", "foo.bar", "example.cz"),
Bud when I'm try use non-ASCI in from like this:
msg['Subject'] = "Subject with non-asci chars like á"
msg['From'] = Address("Fóó Bár", "foo.bar", "example.cz")
msg['To'] = (Address("Fóó Bár", "foo.bar", "example.cz"),
Both from above sending with:
with smtplib.SMTP('localhost') as s:
s.send_message(msg)
I'm get this exception:
smtplib.SMTPNotSupportedError: One or more source or delivery addresses require internationalized email support, but the server does not advertise the required SMTPUTF8 capability`
I know that caused by our's smtp server that does not support SMTPUTF8, but only from non-ASCI display name it shouldn't be necesery.
I assume that you tried to use smtplib.send_message
. It looks like it is much too clever and wants to control whether the server will correctly process utf8 even if as in you use case it is not necessary.
You just have to revert to the good old smtplib.sendmail
:
serv = smtplib.SMTP(mailhost)
serv.sendmail(msg['From'], msg['To'], msg.as_string())