zoukankan      html  css  js  c++  java
  • 【python3】基于 qq邮箱的邮件发送

     脚本内容:

    #!/usr/bin/python3
    # -*- coding: UTF-8 -*-
    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr
     
    send_nickname = '依然范儿特西'   # 发件人昵称
    send_accout='3151775165@qq.com'  # 发件人邮箱账号
    send_pass = '******'   # 发件人邮箱密码
    
    receive_user ='3151775165@qq.com' # 收件人邮箱账号,
    title = "代码改变世界"             #邮件的主题或标题
    
    
    def mail():
        ret=True
        try:
            msg=MIMEText('此处填写邮件内容','plain','utf-8')
            msg['From']=formataddr([send_nickname,send_accout])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
            msg['To']=formataddr(["FK",receive_user])            # 括号里的对应收件人邮箱昵称、收件人邮箱账号
            msg['Subject']=title                                 # 邮件的主题,也可以说是标题
            server=smtplib.SMTP_SSL("smtp.qq.com", 465)          # 发件人邮箱中的SMTP服务器,qq端口是465
            server.login(send_accout, send_pass)                 # 括号中对应的是发件人邮箱账号、邮箱密码
            server.sendmail(send_accout,[receive_user,],msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
            server.quit()  # 关闭连接
        except Exception:  # 如果 try 中的语句没有执行,则会执行下面的 ret=False
            ret=False
        return ret
    ret=mail()
    if ret:
        print("邮件发送成功")
    else:
        print("邮件发送失败")

     发送:

    查看邮件:

  • 相关阅读:
    spring cloud 搭建(服务)
    spring cloud 搭建(配置中心)
    spring cloud 搭建(注册中心)
    spring cloud 搭建
    skywalking 配置和使用(windows)
    jenkins 发布报错
    web 显示 pdf
    springmvc Cacheable 不设置key
    iRed邮箱使用情况
    关闭SSL服务[iRedMail]
  • 原文地址:https://www.cnblogs.com/richerdyoung/p/8426172.html
Copyright © 2011-2022 走看看