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)
    
  • 相关阅读:
    Palindrome Linked List 解答
    Word Break II 解答
    Array vs Linked List
    Reverse Linked List II 解答
    Calculate Number Of Islands And Lakes 解答
    Sqrt(x) 解答
    Find Median from Data Stream 解答
    Majority Element II 解答
    Binary Search Tree DFS Template
    188. Best Time to Buy and Sell Stock IV
  • 原文地址:https://www.cnblogs.com/5haoanqu/p/11131783.html
Copyright © 2011-2022 走看看