zoukankan      html  css  js  c++  java
  • python利用smtp发送邮件

    #!/usr/bin/env python
    # -*- encoding: utf-8 -*-
    # author:IversOn5
    
    import requests
    import json
    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr
    
    def send_mail(Price):
        my_sender='908869236@qq.com'    # 发件人邮箱账号
        my_pass = 'xxxxxx'            # 发件人邮箱密码 这个密码是stmp授权码,请看http://www.runoob.com/python/python-email.html
        my_user='908869236@qq.com'      # 收件人邮箱账号,我这边发送给自己
        ret=True
        try:
            msg=MIMEText('XMR价格已经达到$%s'%str(Price),'plain','utf-8')
            msg['From']=formataddr(["FromRunoob",my_sender])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
            msg['To']=formataddr(["FK",my_user])              # 括号里的对应收件人邮箱昵称、收件人邮箱账号
            msg['Subject']="XMR价格检测报告"                # 邮件的主题,也可以说是标题
    
            server=smtplib.SMTP_SSL("smtp.qq.com", 465)  # 发件人邮箱中的SMTP服务器,端口是25
            server.login(my_sender, my_pass)  # 括号中对应的是发件人邮箱账号、邮箱密码
            server.sendmail(my_sender,[my_user,],msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
            server.quit()  # 关闭连接
            print "It is ok!"
        except Exception:  # 如果 try 中的语句没有执行,则会执行下面的 ret=False
            print "error"
    send_mail(111)
    
  • 相关阅读:
    cuda npp库旋转图片
    Xml序列化 详解
    jsonp简介
    在centos7下安装.net core
    安装vs2017后造成无法打开xproj项目无法打开
    SqlServer 语法
    js自定义事件
    HttpWebResponse 解压gzip、deflate压缩
    centos7 安装.net core的方法
    帮助类-从tfs获取数据
  • 原文地址:https://www.cnblogs.com/5haoanqu/p/11131783.html
Copyright © 2011-2022 走看看