python3.6 发送邮件

import smtplib
from email.mime.text import MIMEText
from email.header import Header

receiver = input(‘输入接收者邮箱\n’)# 暂时不验证
subject = input(‘输入标题\n’)
content = input(‘输入内容\n’)
host =‘smtp.163.com’# 163 SMTP服务器

user_name =’***’# 登录账号 这里是163
pwd =’***’# 设置SMTP所设置的密码
sender = ‘***@163.com’# 发送者邮箱

message = MIMEText(content,‘plain’,‘utf-8’)
message[‘From’] = sender
message[‘to’] = receiver
message[‘Subject’] = subject

try:
smtp_obj = smtplib.SMTP(host,25)
smtp_obj.login(user_name, pwd)
smtp_obj.sendmail(sender, receiver, message.as_string())
print(‘邮件发送成功’)
except smtplib.SMTPException as error:
print(error)
print(‘邮件发送失败’)

你可能感兴趣的:(Util)