使用python发送163邮件

  1. def send_email(title, content):
  2. import smtplib
  3. from email.mime.multipart import MIMEMultipart
  4. from email.mime.text import MIMEText
  5. mail_host = 'smtp.163.com'
  6. mail_user = 'wangjialexxxxxxxx@163.com'
  7. # 这个是授权码 不是密码 需要去163设置
  8. mail_pass = 'wangjialexxxxx'
  9. sender = 'wangjialexxxxxxx@163.com'
  10. receivers = ['wangjialexxxx@163.com']
  11. #构造message (邮件内容)
  12. message = MIMEText(content, 'plain', 'utf-8')
  13. message['Subject'] = title
  14. message['From'] = sender
  15. message['To'] = receivers[0]
  16. # smtp = smtplib.SMTP(mail_host, 587)
  17. try:
  18. #smtp = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信, 端口一般是465
  19. smtp = smtplib.SMTP()
  20. smtp.connect(mail_host)
  21. smtp.set_debuglevel(1)
  22. smtp.ehlo()
  23. smtp.starttls()
  24. smtp.ehlo()
  25. smtp.login(mail_user, mail_pass)
  26. smtp.sendmail(sender, receivers, message.as_string())
  27. smtp.quit()
  28. print("mail has been send successfully.")
  29. except smtplib.SMTPException as e:
  30. print(e)

调用函数

send_email('hello', " 'https://www.cnblogs.com/wangjiale1 024/' ")

qq邮箱

  1. import smtplib
  2. from email import encoders
  3. from email.mime.text import MIMEText
  4. from email.mime.base import MIMEBase
  5. from email.mime.multipart import MIMEMultipart
  6. #sender发件人,password服务器授权码, mail_host 服务器地址(QQsmtp) receiver接收者
  7. sender = 'xxxxxxx@qq.com'
  8. password = '####'
  9. mail_host = 'smtp.qq.com'
  10. receives = [ 'xxxxxxx@xx.com','xxxxxxx1@xx.com','xxxxxxx2@xx.com',]
  11. #设置邮件信息
  12. msg = MIMEMultipart()
  13. #邮件主题
  14. msg['Subject'] = input("请输入邮件主题: ")
  15. msg['From'] = sender
  16. msg_content = input("请输入正文:")
  17. msg.attach(MIMEText(msg_content,'plain','utf-8'))
  18. #登录并发送
  19. try:
  20. s = smtplib.SMTP_SSL("smtp.qq.com", 465)
  21. s.set_debuglevel(1)
  22. s.login(sender, password)
  23. #给接收者发送消息
  24. for i in range(len(receives)):
  25. to = receives[i]
  26. msg['To'] = to
  27. s.sendmail(sender, to, msg.as_string())
  28. print('success!')
  29. s.quit()
  30. print('All email has been send over')
  31. except smtplib.SMTPException as e:
  32. print("Failed ,%s",e)

使用python发送163邮件 qq邮箱的更多相关文章

  1. python 发送163邮件

    可能还需要使用 邮箱第三方客户端的授权码. 网易163免费邮箱相关服务器信息 from email import encoders from email.header import Header fr ...

  2. ThinkPHP 中使用 PHPMailer 发送邮件 支持163和QQ邮箱等

    [摘要]ThinkPHP是一个开源的PHP框架, 是为了简化企业级应用开发和敏捷WEB应用开发而诞生的.本文介绍ThinkPHP 中使用 PHPMailer 发送邮件. PHP是自带可以发送邮件的Ma ...

  3. flask_mail发送163邮件,报553错误的原因

    最近在练习用flask_mail发送163邮件时报错: reply: '553 authentication is required,163 smtp9,DcCowAD3eEQZ561caRiaBA- ...

  4. flask 电子邮件进阶实践-用模板发送163邮件

    电子邮件进阶实践 下面来学习构建邮件的HTML正文,并使用模板组织内容. 一封电子邮件的正文可以是纯文本(text/plain),也可以是HTML格式的文本(text/html).处于全面的考虑,一封 ...

  5. C#使用SMTP协议发送验证码到QQ邮箱

    C#使用SMTP协议发送验证码到QQ邮箱 在程序设计中,发送验证码是常见的一个功能,用户在注册账号时或忘记密码后,通常需要发送验证码到手机短信或邮箱来验证身份,此篇博客介绍在C#中如何使用SMTP协议 ...

  6. 【Python开发】python发送各类邮件的方法

    转载: python发送各类邮件的主要方法 python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法,这里写写自己的的心得,也请高手给些指点. 一.相关模块介绍 发送 ...

  7. JavaMailSender怎么发送163和qq邮件

    https://blog.csdn.net/Tracycater/article/details/73441010 引入Maven依赖包 <dependency> <groupId& ...

  8. 【Python3爬虫】用Python发送天气预报邮件

    此次的目标是爬取指定城市的天气预报信息,然后再用Python发送邮件到指定的邮箱. 一.爬取天气预报 1.首先是爬取天气预报的信息,用的网站是中国天气网,网址是http://www.weather.c ...

  9. python发送给邮件 转

    这里用到了Python的两个包来发送邮件: smtplib 和 email . Python 的 email 模块里包含了许多实用的邮件格式设置函数,可以用来创建邮件“包裹”.使用的 MIMEText ...

随机推荐

  1. Python基础(二):斐波那契数列、模拟cp操作、生成8位随机密码

    一.斐波那契数列 目标: 编写fib.py脚本,主要要求如下: 输出具有10个数字的斐波那契数列 使用for循环和range函数完成 改进程序,要求用户输入一个数字,可以生成用户需要长度的斐波那契数列 ...

  2. MySql插入数据成功但是报[Err] 1055

    1.问题: 这两天做insert操作,mysql版本是5.7,insert后虽然成功了,但是会报一个[Err] 1055的错误.具体如下: 2.解决方案: linux环境下,vim到my.cnf,添加 ...

  3. 探索Redis设计与实现1:Redis 的基础数据结构概览

    本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...

  4. linux 日志文件查看

    记录下日志中常用的日志查看命令. 1.  tail -n 10 -f  **.log 显示日志文件尾部10行日志,当有新日志产生,会追加显示. 2. tail 命令 现ff.sh中有如下信息: [ro ...

  5. 6. 使用cadvisor监控docker容器

    Prometheus监控docker容器运行状态,我们用到cadvisor服务,cadvisor我们这里也采用docker方式直接运行.这里我们可以服务端和客户端都使用cadvisor 客户端 1.下 ...

  6. POJ 1797 Heavy Transportation (最大生成树)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  7. HTTP 请求及响应 (转)

    HTTP请求 4.1.HTTP请求包括的内容 客户端连上服务器后,向服务器请求某个web资源,称之为客户端向服务器发送了一个HTTP请求. 一个完整的HTTP请求包括如下内容:一个请求行.若干消息头. ...

  8. pytest_参数化之3*3

    import pytesttest_user_data1=[{'user':'linda','password':'888888'}, {'user':'servenruby','password': ...

  9. 使用sass

    sass安装 compass安装 1.sass 需要安装ruby,然后通过gem安装sass. 2. less有想=两种安装方: 客户端安装: 引入less.js,然后就可以直接用.less文件 &l ...

  10. sql语句练习50题(Mysql版-详加注释)

    表名和字段 1.学生表       Student(s_id,s_name,s_birth,s_sex) --学生编号,学生姓名, 出生年月,学生性别 2.课程表       Course(c_id, ...