-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsend_mail.py
45 lines (38 loc) · 1.36 KB
/
send_mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: UTF-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart # 一封邮件
import time
'''
126邮箱IMAP/SMTP服务
授权码:RHNLWUVVNXNYCEFX
'''
def sendMail(subject='程序完成情况',msg='您的程序已经运行完成,请去AI Studio查看日志结果',to_list=['[email protected]']):
sender = '[email protected]'
sender_password='密钥'
# 创建邮箱
em = MIMEMultipart()
em['subject'] = subject
em['From'] = sender
em['To'] = ",".join(to_list)
# 邮件的内容
content = MIMEText(msg)
em.attach(content)
# 发送邮件
# 1、连接服务器
# print("开始连接服务器")
#25端口已经被云服务器商关闭了,所以只能用465端口了
smtp=smtplib.SMTP_SSL('smtp.126.com',465)
# print("连接服务器成功")
# 2、登录
# print("开始登录服务器")
smtp.login(sender, sender_password)
# print("登录服务器成功")
# 3、发邮件
# print("开始发送邮件")
smtp.send_message(em)
# print("发送邮件成功")
# 4、关闭连接
smtp.close()
#把'[email protected]' 改为自己的邮箱即可
sendMail(subject='程序完成情况',msg='您的程序已经运行完成,请去AI Studio查看日志结果',to_list=['[email protected]'])