1 Star 0 Fork 20

郑明玉/jenkins-sample

forked from hanxianchao/jenkins-sample 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pro-ok.py 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
hanxianchao 提交于 2024-11-19 02:49 . update pro-ok.py.
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
# 邮件发送配置
smtp_server = 'smtp.163.com' # SMTP服务器地址
smtp_from = '18145536045@163.com' # 发件人邮箱
smtp_auth_username = '18145536045@163.com' # 邮箱用户名
smtp_auth_password = 'NCELIPSDQEAGLHLJ' # 邮箱授权码
recipient_email = '3261593106@qq.com' # 收件人邮箱
def send_email(subject, body):
try:
# 创建邮件对象
message = MIMEMultipart()
message['From'] = Header(smtp_from, 'utf-8')
message['To'] = Header(recipient_email, 'utf-8')
message['Subject'] = Header(subject, 'utf-8')
# 邮件正文(HTML 格式)
message.attach(MIMEText(body, 'html', 'utf-8'))
# 连接SMTP服务器并发送邮件
with smtplib.SMTP(smtp_server, 25) as server:
server.login(smtp_auth_username, smtp_auth_password)
server.sendmail(smtp_from, recipient_email, message.as_string())
print("邮件发送成功!")
except Exception as e:
print(f"邮件发送失败:{e}")
# 测试发送
if __name__ == "__main__":
subject = "代码部署到生产环境确认邮件"
body = (
"""
<p>运维同事,您好,</p>
<p>测试环境目前测试代码没问题,是否同意部署到生产环境?</p>
<p>如果同意,请点击以下链接登录 Jenkins,将代码部署到生产环境:</p>
<p><a href="http://192.168.40.180:30002/job/jenkins-harbor" target="_blank">
http://192.168.40.180:30002/job/jenkins-harbor</a></p>
<p><br>邮件由测试团队发送</p>
"""
)
send_email(subject, body)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/zheng-mingyu/jenkins-sample.git
git@gitee.com:zheng-mingyu/jenkins-sample.git
zheng-mingyu
jenkins-sample
jenkins-sample
master

搜索帮助