本帖最后由 涛之雨 于 2023-7-21 11:26 编辑
[Python] 纯文本查看 复制代码 import smtplib
from email.mime.text import MIMEText
from email.header import Header
import requests
from bs4 import BeautifulSoup
def sead_email():
accout='**'
destination='**'
password='**'
# 获取百度页面的内容
response = requests.get("https://www.baidu.com/")
response.encoding = 'utf-8'
baidu_content = response.text
soup=BeautifulSoup(baidu_content,'html.parser')
body_content=str(soup.body)
#'''
#with open('www.baidu.com','r',encoding='utf8') as f:
# file_content=f.read()
# 将邮件内容设置为HTML格式
message = MIMEText(body_content, 'html', 'utf-8')
message['From']=Header(destination,'utf-8')
message['Subject']=Header('Python SMTP 测试','utf8')
print('准备发送')
try:
server = smtplib.SMTP_SSL("smtp.qiye.163.com",465)
print('已经连接正在登入')
server.login(accout,password)
print('账号登入成功')
server.sendmail(accout,destination,message.as_string())
print('succsesfully')
except Exception as e:
print('失败',str(e))
finally:
if server:
server.quit()
sead_email()
邮件内容是这样的,但是我想要的是百度页面完整的
|