-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendemail.py
68 lines (61 loc) · 2.01 KB
/
sendemail.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# import smtplib
# from email.mime.text import MIMEText
# from email.header import Header
# sender = 'from@runoob.com'
# receivers = ['429240967@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
# # 三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码
# message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')
# message['From'] = Header("菜鸟教程", 'utf-8')
# message['To'] = Header("测试", 'utf-8')
# subject = 'Python SMTP 邮件测试'
# message['Subject'] = Header(subject, 'utf-8')
# try:
# smtpObj = smtplib.SMTP('localhost')
# smtpObj.sendmail(sender, receivers, message.as_string())
# print "邮件发送成功"
# except smtplib.SMTPException:
# print "Error: 无法发送邮件"
import sys
import smtplib
from email.mime.text import MIMEText
# 定义发送列表
mailto_list=["yulong.rong@fanyoy.com"]
# 设置服务器名称、用户名、密码以及邮件后缀
mail_host = "smtp.exmail.qq.com"
mail_user = "quanming.zhang@fanyoy.com"
mail_pass = "Fanyou$11"
mail_postfix="qq.com"
# 发送邮件函数
def send_mail(to_list, sub, context):
'''''
to_list: 发送给谁
sub: 主题
context: 内容
send_mail("xxx@126.com","sub","context")
'''
me = mail_user + "<"+mail_user+">"
print me
msg = MIMEText(context)
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
send_smtp = smtplib.SMTP()
send_smtp.connect(mail_host)
send_smtp.login(mail_user, mail_pass)
send_smtp.sendmail(me, to_list, msg.as_string())
send_smtp.close()
return True
except Exception as e:
print(str(e))
return False
if __name__ == '__main__':
print "aaa"
ip0 = sys.argv[1]
ip = sys.argv[2]
if (True == send_mail(mailto_list,"IP变动","外网IP已变,原IP:%s,现IP:%s" % (ip0,ip))):
print ("测试成功")
else:
print ("测试失败")