python email smtplib模块发送邮件代码实例

作者:laozhang 时间:2022-05-15 16:37:03 

本例使用 QQ邮箱测试,需要打开 QQ邮箱的 smtp协议,获取授权码

代码内容如下:


#!/usr/bin/env python
# _*_ coding:utf-8 _*_
__author__ = 'junxi'

import smtplib
from email.mime.text import MIMEText

# 文本模式
# msg = MIMEText('send by python...', 'plain', 'utf-8')
# html 格式
msg = MIMEText('<html><body><h1>Hello</h1>' + '<p>send by <a href="http://www.xuegod-for.cn/yum" rel="external nofollow" >python</a></body></html>', 'html', 'utf-8')
msg['From'] = "xiaoxinxxxx@qq.com"
msg["To"] = "xinleixxxx@126.com"
msg["Subject"] = "python test"

server = smtplib.SMTP_SSL('smtp.qq.com', 465)
server.set_debuglevel(1)
# xxxxxxxxx 是在QQ邮箱获取的授权码, 如果不需要授权的邮箱直接输入密码即可
server.login("xiaoxinxxxx@qq.com", "xxxxxxxxx")
server.sendmail("xiaoxinxxxx@qq.com",["xinleixxxx@126.com"],msg.as_string())
server.quit()

查看结果:

python email smtplib模块发送邮件代码实例

标签:python,smtplib
0
投稿

猜你喜欢

  • python3爬虫中引用Queue的实例讲解

    2023-07-15 19:43:48
  • python解析PDF程序代码

    2021-05-17 03:16:55
  • html+css+js实现别踩白板小游戏

    2023-09-02 10:05:42
  • 浅谈python 中的 type(), dtype(), astype()的区别

    2022-09-13 22:40:39
  • Python脚本实现自动登录校园网

    2023-01-26 09:37:56
  • Python生成pdf目录书签的实例方法

    2023-10-11 15:43:21
  • Python3.7.0 Shell添加清屏快捷键的实现示例

    2023-02-25 13:39:23
  • python [:3] 实现提取数组中的数

    2022-06-29 07:46:19
  • 怎样从旧版本SQL Server中重新存储数据

    2009-01-15 13:23:00
  • 一个统计当前在线用户的解决方案

    2007-10-13 19:27:00
  • Oracle 8i字符集乱码问题析及其解决办法

    2010-07-26 13:29:00
  • Win10下python 2.7与python 3.7双环境安装教程图解

    2022-12-14 06:03:16
  • Python安装selenium包详细过程

    2023-04-12 00:05:31
  • python实现canny边缘检测

    2022-03-05 00:24:08
  • Python后台开发Django会话控制的实现

    2022-11-09 22:29:16
  • Python3使用PySynth制作音乐的方法

    2021-03-18 19:41:01
  • python通过tcp发送xml报文的方法

    2021-02-18 08:34:25
  • Python变量和数据类型详解

    2022-01-25 07:26:25
  • PDO::errorCode讲解

    2023-06-08 03:39:17
  • 用doctype激活浏览器模式

    2009-06-15 19:02:00
  • asp之家 网络编程 m.aspxhome.com