下面一段简短代码给大家介绍python 3实现发送邮件功能,具体代码如下所示:
import smtplib from email.mime.text import MIMEText 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("mail has been send successfully.") except smtplib.SMTPException as e: 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="i love u, i love python,你好" #邮件内容 # msg=MIMEText(message)#转换邮件文本 # # msg['Subject']="hello gogogogogogo" #标题 # 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")
总结
以上所述是小编给大家介绍的使用python 3实现发送邮件功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!