Python_Automation_04Email_smtplib

sina 发QQ, 百度来的,改改可用,smtplib

 

import smtplib
from email.mime.text import MIMEText

# 第三方 SMTP 服务
mail_host = "smtp.sina.com"  # SMTP服务器
mail_user = ""  # 用户名
mail_pass = ""  # 密码

sender = '@sina.com'  # 发件人邮箱(最好写全, 不然会失败)
receivers = [''# 接收邮件,可设置为你的QQ邮箱或者其他邮箱
receivers1 =['']
content = '哈哈,学习的代码!'
title = 'Python SMTP Mail Test'  # 邮件主题
message = MIMEText(content, 'plain', 'utf-8'# 内容, 格式, 编码
message['From'] = "{}".format(sender)
message['To'] = ",".join(receivers)
message['Subject'] = title

try:
  
smtpObj = smtplib.SMTP_SSL(mail_host, 465)  # 启用SSL发信, 端口一般是465
  
smtpObj.login(mail_user, mail_pass)  # 登录验证
  
smtpObj.sendmail(sender, receivers1, message.as_string())  # 发送
  
print("mail has been send successfully.")
except smtplib.SMTPException as e:
  
print(e)
   print('failed')

 

posted @ 2017-01-23 15:59  木石1987  阅读(158)  评论(0编辑  收藏  举报