python3 mail

import smtplib
from email.mime.text import MIMEText

mailto_list=["[email protected]"]
mail_host="smtp.kuanrf.com"
mail_user="XXXXXX"
mail_pass="XXXXXX"
mail_postfix="kuanrf.com"

def send_mail(to_list,sub,content):
	me="hello"+"<"+mail_user+"@"+mail_postfix+">"
	msg=MIMEText(content,_subtype="html",_charset="gb2312")
	msg["Subject"]=sub
	msg["From"]=me
	msg["To"]=";".join(to_list)
	try:
		s=smtplib.SMTP()
		s.connect(mail_host)
		s.login("[email protected]","XXXXXX")
		s.sendmail(me,to_list,msg.as_string())
		s.close()
		return True
	except Exception as e:
		print(str(e))
		return False
	
if __name__=="__main__":
	if send_mail(mailto_list,"hello","kkkkkk"):
		print("success")
	else:
		print("faild")

你可能感兴趣的:(python)