zoukankan      html  css  js  c++  java
  • 发送邮件小工具(python)

    #!/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
    %s' %('
    '.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)
  • 相关阅读:
    SSM框架--详细整合教程
    ssh--整合注意事项
    SSH--三大框架整合原理
    springMVC的流程
    java框架问题整理
    集合的体系
    java异常机制
    java知识点
    Java编程思想【Thinking in java】
    实验三 指令实验(一)
  • 原文地址:https://www.cnblogs.com/stin/p/7851887.html
Copyright © 2011-2022 走看看