#!/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 ("Xx@xx", "Heading 1", "Test 1")
This article is from the "I Love Technology" blog, please be sure to keep this source http://zhoulinjun.blog.51cto.com/3911076/1585687
Python sends a Chinese message