sendmail

def send_mail( sub, content):
to_list = ['xxwf638368@163.com', 'grhgrh8676@126.com']
mail_host = "smtp.163.com"
mail_user = "xxwf638368"
    mail_pass = "52877637"
mail_postfix = "163.com"

me = "hello" + "<" + mail_user + "@" + mail_postfix + ">"
msg = MIMEText(content, _subtype='plain', _charset='gb2312')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user, mail_pass)
server.sendmail(me, to_list, msg.as_string())
server.close()
return True
except Exception as e:
print(str(e))
return False
posted @ 2017-06-08 18:36  wangxingg  阅读(143)  评论(0)    收藏  举报