-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaliSendMail.py
More file actions
48 lines (37 loc) · 1.04 KB
/
aliSendMail.py
File metadata and controls
48 lines (37 loc) · 1.04 KB
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
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2018-12-26 15:41
# @Author : opsonly
# @Site :
# @File : aliSendMail.py
# @Software: PyCharm
import smtplib
import sys
from email.mime.text import MIMEText
from email.utils import formataddr
#发件人邮箱账号
my_sender = 'xxxxxxxxxx'
#发件人第三方客户端授权码
my_pass = 'xxxxxxxxxxxxx'
#收件人邮箱账号
my_user = 'xxxxxxxxxxxx@xxxx.com'
#接收参数并定义标题和内容
subject = sys.argv[1]
context = sys.argv[2]
def mail():
mail_msg = context
#发送信息
msg = MIMEText(mail_msg, 'html', 'utf-8')
msg['From'] = formataddr(["dashui", my_sender])
msg['To'] = formataddr(["dashui", my_user])
msg['Subject'] = subject
#因为阿里云25号端口默认关闭,采用465端口
server = smtplib.SMTP_SSL("smtp.163.com", 465)
server.login(my_sender, my_pass)
server.sendmail(my_sender, [my_user, ], msg.as_string())
server.quit()
try:
mail()
print('邮件发送成功')
except:
print('邮件发送失败')