Qi-gege
#coding=utf-8
\'\'\'
Created on 2017-7-5
@auther:Qigege
Project:发送邮箱测试

\'\'\'
import smtplib
from email.mime.text import MIMEText

#SMTP服务器
mail_host=\'smtp.163.com\'
mail_user=\'******@163.com\'
#网易邮箱为网页版,需要用到客户端密码,进入网页版邮箱中设置授权码,即客户端密码
mail_password=\'******\'

#发件人邮箱
sender=\'******@163.com\'
#接收人邮箱
receiver=[\'******@qq.com\',\'******@qq.com\']

content=u\'邮箱测试......\' #内容
title=\'Python SMTP Mail Test\' #主题
message=MIMEText(content,\'plain\',\'utf-8\')
#邮箱发送者地址
#格式化字符串format(),{}==%,例:‘{1}{0}{1}’.format(\'abc\',12)-->\'12,abc,12\'
message[\'From\']=\'{}\'.format(sender)
#邮件接受者地址,字符串列表[‘接受地址1’接受地址2’......]接受地址
message[\'To\']=\',\'.join(receiver) #type(message[\'To\'])str
message[\'Subject\']=title

try:
#启用SSL,端口一般是465
smtpObj=smtplib.SMTP_SSL(mail_host,465)
#登录验证
smtpObj.login(mail_user,mail_password)
#发送
smtpObj.sendmail(sender,receiver,message.as_string())
#as_string()MIMETextMIMEMultipart对象转换为str
print \'mail has been send successfully.\'
except smtplib.SMTPException as e:
print e

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2021-09-17
  • 2022-02-09
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-13
  • 2021-12-30
  • 2021-12-03
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案