首页 > 代码库 > python 发送中文邮件

python 发送中文邮件

#!/usr/bin/python

#coding:utf-8


import smtplib

from email.Header import Header

from email.MIMEText import MIMEText


mail_host = ‘smtp.163.com‘

mail_user = ‘user‘

mail_pass = ‘password‘

mail_postfix = ‘163.com‘


def send_mail(to_list,subject,content):

        me = mail_user+"<"+mail_user+"@"+mail_postfix+">"

        msg = MIMEText(content,‘plain‘,‘utf-8‘)

        msg[‘Subject‘] = Header(subject,‘utf-8‘)

        msg[‘From‘] = me

        msg[‘To‘] = to_list+"<"+to_list+">"

        try:

                s = smtplib.SMTP()

                s.connect(mail_host)

                s.login(mail_user,mail_pass)

                s.sendmail(me,to_list,msg.as_string())

                s.close()

                return True

        except Exception,e:

                print str(e)

                return False

if __name__ == "__main__":


        send_mail("××@××", "标题1","测试1")


本文出自 “我爱技术” 博客,请务必保留此出处http://zhoulinjun.blog.51cto.com/3911076/1585687

python 发送中文邮件