from time import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
def sendmail():
# 发送邮箱服务器
smtpserver = ""
# 发送邮箱用户名密码
user = ""
password = ""
# 发送和接收邮箱
sender = ""
#receive = ""
receive = ""
# 发送邮件主题和内容
subject = "dasfowefe"
content = "<html><h1 style='color:red'>zabbixdjflajdflkajfklasjdfklasjdlf</h1></html>"
msgRoot = MIMEMultipart()
send_file = open(r"/root/{}".format("aa.sh"), "rb").read()
att = MIMEApplication(send_file, )
att['Content-Type'] = 'application/octet-stream'
att.add_header('Content-Disposition', 'attachment', filename='{}'.format("aa.sh"))
msgRoot.attach(MIMEText(content, 'html', 'utf-8'))
msgRoot['Subject'] = subject
msgRoot['From'] = sender
msgRoot['To'] = ''.join(receive)
msgRoot.attach(att)
# SSL协议端口号要使用465
smtp = smtplib.SMTP_SSL(smtpserver, 465)
# HELO向服务器标志用户身份
smtp.helo(smtpserver)
# 服务器返回结果确认
smtp.ehlo(smtpserver)
# 登录邮箱服务器用户名密码
smtp.login(user, password)
print("Send email start...")
smtp.sendmail(sender, receive, msgRoot.as_string())
smtp.quit()
print("email send end!")
sendmail()
python 邮件
最新推荐文章于 2025-04-23 20:20:47 发布
该博客展示了如何使用Python的smtplib和email库发送带有附件的HTML格式邮件。通过SMTP_SSL建立SSL连接,设置邮件主题、内容,并附加一个名为'aa.sh'的文件。邮件内容包含HTML标签,用于格式化文本。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Python3.9
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
1417

被折叠的 条评论
为什么被折叠?



