python发送邮件脚本
#!/usr/bin/python# -*- coding: UTF-8 -*-import sysimport smtplibimport email.mime.multipartimport email.mime.textserver = 'smtp.126.com'#发送服务器port = '25'#发送端口def sendm...
·
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import smtplib
import email.mime.multipart
import email.mime.text
server = 'smtp.126.com' #发送服务器
port = '25' #发送端口
def sendmail(server,port,user,pwd,msg):
smtp = smtplib.SMTP()
smtp.connect(server,port)
smtp.login(user, pwd)
smtp.sendmail(msg['from'], msg['to'], msg.as_string())
smtp.quit()
print('邮件发送成功email has send out !')
if __name__ == '__main__':
msg = email.mime.multipart.MIMEMultipart()
msg['Subject'] = '服务器报警请注意!'
msg['From'] = 'ron@126.com' #发送者邮箱
msg['To'] = 'xxx@139.com' #接收者邮箱
user = 'ron' #发送者邮箱用户名
pwd = 'password' #发送者邮箱密码
content='%s\n%s' %('\n'.join(sys.argv[1:4]),' '.join(sys.argv[4:])) #格式处理,专门针对我们的邮件格式
txt = email.mime.text.MIMEText(content, _charset='utf-8')
msg.attach(txt)
sendmail(server,port,user,pwd,msg)
更多推荐
已为社区贡献2条内容
所有评论(0)