资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么在python3.5中使用email发送邮件-创新互联

这篇文章将为大家详细讲解有关怎么在python3.5 中使用email发送邮件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联专业为企业提供米易网站建设、米易做网站、米易网站设计、米易网站制作等企业网站建设、网页设计与制作、米易企业网站模板建站服务,十余年米易做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。python有哪些常用库

python常用的库:1.requesuts;2.scrapy;3.pillow;4.twisted;5.numpy;6.matplotlib;7.pygama;8.ipyhton等。

from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email import encoders
import smtplib
import time


def send_mail(subject):
 email_host = '' # 服务器地址
 sender = '' # 发件人
 password = '' # 密码,如果是授权码就填授权码
 receiver = '' # 收件人

 msg = MIMEMultipart()
 msg['Subject'] = subject # 标题
 msg['From'] = '' # 发件人昵称
 msg['To'] = '' # 收件人昵称

 signature = '''
\n\t this is auto test report!
\n\t you don't need to follow
'''
 # text = MIMEText(signature, 'plain') # 签名
 # msg.attach(text)

 # 正文-图片 只能通过html格式来放图片,所以要注释25,26行
 mail_msg = '''

\n\t this is auto test report!

\n\t you don't need to follow

我的博客:

截图如下:

'''  msg.attach(MIMEText(mail_msg, 'html', 'utf-8'))  # 指定图片为当前目录  fp = open(r'111.jpg', 'rb')  msgImage = MIMEImage(fp.read())  fp.close()  # 定义图片 ID,在 HTML 文本中引用  msgImage.add_header('Content-ID', '')  msg.attach(msgImage)  ctype = 'application/octet-stream'  maintype, subtype = ctype.split('/', 1)  # 附件-图片  image = MIMEImage(open(r'111.jpg', 'rb').read(), _subtype=subtype)  image.add_header('Content-Disposition', 'attachment', filename='img.jpg')  msg.attach(image)  # 附件-文件  file = MIMEBase(maintype, subtype)  file.set_payload(open(r'320k.txt', 'rb').read())  file.add_header('Content-Disposition', 'attachment', filename='test.txt')  encoders.encode_base64(file)  msg.attach(file)  # 发送  smtp = smtplib.SMTP()  smtp.connect(email_host, 25)  smtp.login(sender, password)  smtp.sendmail(sender, receiver, msg.as_string())  smtp.quit()  print('success') if __name_- == '__main__':  now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))  subject = now + '自动化测试报告'  send_mail(subject)

关于怎么在python3.5 中使用email发送邮件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


文章标题:怎么在python3.5中使用email发送邮件-创新互联
浏览地址:http://cdkjz.cn/article/dsheec.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220