#!/usr/bin/python # -*- coding:UTF-8 -*- import sys import smtplib import email.mime.multipart import email.mime.text server = \'smtp.163.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\'] = \'18521309001@163.com\' msg[\'To\'] = \'xusujuan1989@126.com\' user = \'18521309001\' pwd = \'123qwe\' #客户端授权密码,非邮箱密码 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)
发送邮件小工具(python)
内容版权声明:除非注明,否则皆为本站原创文章。