使用python 3实现发送邮件功能
下面一段简短代码给大家介绍python3实现发送邮件功能,具体代码如下所示:
importsmtplib
fromemail.mime.textimportMIMEText
SMTPsever="smtp.163.com"#邮箱服务器
sender="**********@163.com"#邮件地址
password="Whl3386087"#密码
receivers=["********@qq.com"]
content='端午节快乐哈哈\n邮箱轰炸机的问候'
title='端午节问候'#邮件主题
message=MIMEText(content,'plain','utf-8')#内容,格式,编码
message['From']="{}".format(sender)
message['To']=",".join(receivers)
message['Subject']=title
#mailsever=smtplib.SMTP(SMTPsever,25)#服务器端口
#mailsever.login(sender,password)#登陆
try:
mailsever=smtplib.SMTP_SSL(SMTPsever,465)#启用SSL发信,端口一般是465
mailsever.login(sender,password)#登录验证
mailsever.sendmail(sender,receivers,message.as_string())#发送
print("mailhasbeensendsuccessfully.")
exceptsmtplib.SMTPExceptionase:
print(e)
mailsever.quit()
print("OK")
#SMTPServer="smtp.163.com"#服务器
#Sender="wangh78uanl78ong1995@.163.com"
#Password="Whl33788608787"
#Message="端午节快乐哈哈\n邮箱轰炸机的问候"
#msg=MIMEText(Message)
#msg["Subject"]="端午节问候"#标题
#msg["From"]=Sender
#msg["To"]=Addressee
#
#mailsever=smtplib.SMTP(SMTPServer,25)#服务器端口
#
#mailsever.login(Sender,Password)
#mailsever.sendmail(Sender,["1388810811154@163.com","wang88huanlong1995@.163.com"],msg.as_string())
#mailsever.quit()
#
#print("运行完成")
#SMTPsever="smtp.qq.com"#邮箱服务器
#sender="wang7hu8anlo88ng19795@qq.com"#邮件地址
#password="edzzeqpdor8cwgiab"#密码
#
#message="iloveu,ilovepython,你好"#邮件内容
#msg=MIMEText(message)#转换邮件文本
#
#msg['Subject']="hellogogogogogogo"#标题
#msg['From']=sender#谁发的
#msg['To']="86185854829@qq.com"#接收
#88
#mailsever=smtplib.SMTP(SMTPsever,587)#服务器端口
#mailsever.login(sender,password)#登陆
#mailsever.sendmail(sender,["wang8hau8nlo88g19985@163.com","1105436888599@qq.com"],msg.as_string())#发送
#mailsever.quit()8
#print("OK")
总结
以上所述是小编给大家介绍的使用python3实现发送邮件功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!