forked from ZiYang-xie/FduCourseSelector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_sender.py
More file actions
35 lines (32 loc) · 926 Bytes
/
email_sender.py
File metadata and controls
35 lines (32 loc) · 926 Bytes
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
#coding=UTF-8
import smtplib
from email.mime.text import MIMEText
def sendEmail(info):
#设置服务器所需信息
#163邮箱服务器地址
mail_host = 'smtp.163.com'
#163用户名
mail_user = ''
#密码(部分邮箱为授权码)
mail_pass = ''
sender = ''
receivers = ['']
#设置email信息
#邮件内容设置
message = MIMEText(info,'plain','utf-8')
message['Subject'] = '【选课脚本通知】'
message['From'] = sender
message['To'] = receivers[0]
#登录并发送邮件
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host,25)
smtpObj.login(mail_user,mail_pass)
#发送
smtpObj.sendmail(
sender, receivers, message.as_string())
#退出
smtpObj.quit()
print('success')
except smtplib.SMTPException as e:
print('error',e) #打印错误