06.07.2020 · The smtplib module. The smtplib is a Python library for sending emails using the Simple Mail Transfer Protocol (SMTP). The smtplib is a built-in module; we do not need to install it. It abstracts away all the complexities of SMTP. Mail servers. To actually send an email, we need to have access to a mail server.
I wish to use Python's email module to change the encoding of MIME mail message parts from quoted-printable or base64 to 7bit or 8bit.All seems to work out, except that at the end, for some messages, email.message.as_string encodes some parts (text/plain and text/html both encountered) as base64.I do not understand why, and what to understand this behavior to avoid it.
I keep getting the [AttributeError: 'list' object has no attribute 'encode'] error ... 'password') text = msg.as_string() smtpObj.sendmail(fromaddr, ...
The same as the as_string() method. name in m Returns True if name is the name ofa header in the message. Finally, a Message object has a few attributes, ...
26.06.2014 · s = smtplib.SMTP('localhost') s.sendmail(me, [you], msg.as_string()) s.quit() You have to convert the MIMEText into a string for sendmail to be happy. After fixing the subject bug that @jdi pointed out (which generates an "AttributeError: 'tuple' object has no attribute 'lstrip'" message) and changing msg to msg.as_string(), your code works for me.
This issue is now closed. The as_string method in mime classes in module email.mime use base64 to encode the text, but segmentedly while the text contents non-acsii characters and is in type of unicode. This behavior confuse some of the email servers.