首页 > 代码库 > 通过SMTP发送邮件的Python代码
通过SMTP发送邮件的Python代码
贴上一段用Python开发的发送邮件程序
#coding=UTF-8import smtplibfrom email.mime.text import MIMETextsmtp_host="smtp.163.com"smtp_port="25"mail_user="yhtt2020@163.com"mail_password="1111222"def send_mail(to_list,subject,content):charset = ‘UTF-8‘msg = MIMEText(content,_subtype=‘html‘,_charset=charset)msg[‘Subject‘] = subjectmsg[‘From‘] = mail_usermsg[‘To‘] = ‘,‘.join(to_list)try:s = smtplib.SMTP(smtp_host, smtp_port)s.ehlo()#s.starttls()#s.ehlo()s.login(mail_user, mail_password)print ‘success in login...‘s.sendmail(mail_user, to_list, msg.as_string())s.close()print ‘success in sending...‘return Trueexcept Exception, e:print ‘failed in sending...‘print str(e)return Falsesend_mail(‘597964799@qq.com,yhsol1@163.com‘.split(‘,‘),‘我的邮件发送测试‘,‘THIS IS A TEST MAIL 这是测试邮件的内容‘)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。