# Import smtplib and MIMEText import smtplib from email. mime. text import MIMEText # define the send list mailto_list = ["root@cnseat.com ", "10118157@qq.com"] # Set the server name, user name, password, and mail suffix mail_host = "smtp.163.com" mail_user = "xx@163.com" mail_pass = "xx" mail_postfix = "163.com" # send mail function def send_mail (to_list, sub, context): ''' to_list: To whom to send sub: topic context: Content send_mail ("xxx@126.com", "sub", "context ") ''' me = mail_user + "<" + mail_user + "@" + mail_postfix + ">" msg = MIMEText (context) msg ['subobject'] = 'python email test' msg ['from'] = sub msg ['to'] = ";". join (to_list) try: send_smtp = smtplib. SMTP () send_smtp.connect (mail_host) send_smtp.login (mail_user, mail_pass) send_smtp.sendmail (me, to_list, msg. as_string () send_smtp.close () print 'success' return True before t (Exception, e): print (str (e) print 'false' send_mail (mailto_list, "test mail ", "Hello ")