Skip to content Skip to sidebar Skip to footer

Python - Sending Arabic E-mails Using Smtplib

I'm trying to send and email including Arabic and Persian characters, using smtplib. The Following is my Function: def send_email (admin, pwd, user, message): server = smtplib.

Solution 1:

try .encode('UTF-8') hope it'll help

Solution 2:

The following code should solve your problem:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import smtplib
import email.mime.text

    def send_email (admin, pwd, user, message):
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.ehlo()
        server.starttls()
        server.login(admin, pwd)
        server.sendmail(admin, user, message)
        server.close()
        return True

    msg = email.mime.text.MIMEText("پایتون", _charset="UTF-8")
    print send_email('send@gmail.com', 'passwd', 'rec@gmail.com', msg.as_string())`

Post a Comment for "Python - Sending Arabic E-mails Using Smtplib"