1 Star 0 Fork 20

Chenchen666/jenkins-sample

forked from hanxianchao/jenkins-sample 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
smtp.py 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
Chenchen666 提交于 2024-12-10 09:27 . update smtp.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 = '15980267200@163.com' # 发件人邮箱
smtp_auth_username = '15980267200@163.com' # 邮箱用户名
smtp_auth_password = 'ZSi7p47RxQrNHca6' # 邮箱授权码
recipient_email = '15980267200@139.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')
# 邮件正文
message.attach(MIMEText(body, 'plain', '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 = (
"各位好,\n\n"
"代码已经成功发布到生产环境(production)。\n"
"请访问以下路由,确认返回内容是否正常:\n"
"http://192.168.40.180:31890\n\n"
"如有问题请及时反馈!\n\n"
"此致,\运维团队"
)
send_email(subject, body)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/chenc66666/jenkins-sample.git
git@gitee.com:chenc66666/jenkins-sample.git
chenc66666
jenkins-sample
jenkins-sample
master

搜索帮助