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

yipeiwu_com6年前Python基础

本例使用 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()

查看结果:

相关文章

Django中cookie的基本使用方法示例

前言 基于 Internet的各种服务系统应运而生,建立商业站点或者功能比较完善的个人站点,常常需要记录访问者的一些信息;论坛作为 Internet发展的产物之一,在 Internet...

基于python list对象中嵌套元组使用sort时的排序方法

在list中嵌套元组,在进行sort排序的时候,产生的是原数组的副本,排序过程中,先根据第一个字段进行从小到大排序,如果第一个字段相同的话,再根据第二个字段进行排序,依次类推,当涉及到字...

Python实现FTP弱口令扫描器的方法示例

Python实现FTP弱口令扫描器的方法示例

FTP服务器 FTP服务器是在互联网上提供文件存储和访问服务的计算机,它们依照FTP协议提供服务。FTP是File Transfer Protocol(文件传输协议)的缩写。顾名思义,...

对pandas的层次索引与取值的新方法详解

对pandas的层次索引与取值的新方法详解

1、层次索引 1.1 定义 在某一个方向拥有多个(两个及两个以上)索引级别,就叫做层次索引。 通过层次化索引,pandas能够以较低维度形式处理高纬度的数据 通过层次化索引,可以按照层次...

Python version 2.7 required, which was not found in the registry

Python version 2.7 required, which was not found in the registry

安装PIL库的时候,直接提示:Python version 2.7 required, which was not found in the registry。 如图: 大意是说找不到...