selenium+python smtp邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium+python smtp邮件相关的知识,希望对你有一定的参考价值。

#code:utf-8

import smtplib from email.mime.text import MIMEText

from email.mime.multipart import MIMEMultipart

from email.header import Header

smtpserver = ‘smtp.163.com‘

smtp_user = ‘*******‘

smtp_pass = ‘*******‘

from_addr=‘**********@163.com‘

to_addr= ‘********@qq.com‘

subject = ‘休假申请‘

#message = MIMEMultipart()

message = MIMEText(‘这是今天的休假申请‘,‘plain‘,‘utf-8‘)

message[‘Subject‘] = Header(subject,‘utf-8‘)

message[‘From‘] = from_addr

message[‘To‘] = to_addr

#注释部分为带附件的代码

#message.attach(message_text)

#att1=MIMEText(open(‘test.txt‘,‘rb‘).read(),‘base64‘,‘utf-8‘)

#att1[‘Content-Type‘] = ‘application/octet-stream‘

#att1[‘Content-Disposition‘] = ‘attachment:filename="test.txt"‘

#message.attach(att1)

sm=smtplib.SMTP()

sm.connect(smtpserver,25)

sm.login(smtp_user,smtp_pass)

sm.sendmail(from_addr,to_addr,message.as_string())

sm.quit()

以上是关于selenium+python smtp邮件的主要内容,如果未能解决你的问题,请参考以下文章

python selenium-7自动发送邮件

selenium - SMTP发送邮件 - 环境配置

selenium - SMTP发送邮件 - 完整示例demo

Python发邮件

Python 通过 SMTP 发送邮件

Python SMTP发送邮件