06 August 2015

smtplib handle non-ascii

email_body_msg = "victim’s reach"

char between m and s is non ascii character.

smtplib (python) cannot handle this. So what is the solution?

Simple solution, Just convert all the email_body_msg to base64. 

1) Use another python lib:
     from email.mime.text import MIMEText

2) Use UTF-8
     message = MIMEText(email_body_msg, _charset="UTF-8")

3) convert MIMEText back to string
    smtplib.SMTP.sendmail(self.mfrom, receivers, message.as_string())

good read:

No comments:

Post a Comment

Terima kasih