python实现邮件发送功能
发布时间:2020-12-20 10:13:17 所属栏目:Python 来源:网络整理
导读:? ? import smtplibimport email.mime.multipartimport email.mime.textdef send_email(receiver,content): msg = email.mime.text.MIMEText(content,‘html‘,‘utf-8‘) msg[‘from‘] = ‘[email?protected]‘ # 从该邮箱发送 msg[‘to‘] = receiver #
? ? import smtplib import email.mime.multipart import email.mime.text def send_email(receiver,content): msg = email.mime.text.MIMEText(content,‘html‘,‘utf-8‘) msg[‘from‘] = ‘[email?protected]‘ # 从该邮箱发送 msg[‘to‘] = receiver # 发送到该邮箱 msg[‘subject‘] = ‘Python自动邮件‘ smtpSever = ‘smtp.qq.com‘ # 163邮箱的smtp Sever地址 smtpPort = ‘25‘ # 开放的端口 sqm = ‘acsinwaqcutkbbha‘ # 在登录smtp时需要login中的密码应当使用授权码而非账户密码 smtp = smtplib.SMTP() # 服务器连接并登陆 smtp.connect(smtpSever,smtpPort) smtp.login(msg[‘from‘],sqm) # 发邮件 smtp.sendmail(msg[‘from‘],msg[‘to‘],str(msg)) print(str(msg)) smtp.quit() content="tester" send_email("[email?protected]",content) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |