关于python3 发送邮件
一:发送文本信息
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL #qq服务器
host_server = 'smtp.qq.com'
#sender_qq为发件人的qq号码
sender_qq = '**263357**'
#qpass为qq邮箱的授权码
qpass = 'iajfnsdabvjxh***'
#发件人的邮箱
sender_qq_mail = '**2633573**@qq.com'
#收件人邮箱
receiver = '***5228***@qq.com'
#发送邮件的正文内容
mail_content = '邮箱测试'
#发送邮件标题
mail_title = 'python的邮件' #ssl登录qq邮箱
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq,qpass) #发送邮件
msg = MIMEText(mail_content, "plain", 'utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
二:发送邮件带附件
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from smtplib import SMTP_SSL #qq邮箱smtp服务器
host_server = 'smtp.qq.com'
#sender_qq为发件人的qq号码
sender_qq = '**263357**'
#qpass为qq邮箱的授权码
qpass = 'iajfnsdabvjxh***'
#发件人的邮箱
sender_qq_mail = '**263357**@qq.com'
#收件人邮箱
receiver = '***6643***@qq.com'
#邮件的正文内容
mail_content = '邮箱测试'
#邮件标题
mail_title = 'python的邮件' #ssl登录
smtp = SMTP_SSL(host_server)
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq,qpass) msg= MIMEMultipart()
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
msg.attach(MIMEText(mail_content, "plain", 'utf-8')) # 附件,当前目录下的 test.txt 文件
att1 = MIMEText(open('test.txt', 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写
att1["Content-Disposition"] = 'attachment; filename="test.txt"'
msg.attach(att1) smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
关于python3 发送邮件的更多相关文章
- 用Python3发送邮件详解
[整个邮件系统是怎样工作的] 邮件自互联网诞生之初就有了,它和web服务一样也是采用的c/s架构,比如我们常见的邮件客户端有outlook.foxmail这些邮件客户端软件. 当我们要发邮件时客户端就 ...
- Python3发送邮件功能
Python3实现邮件发送功能 import smtplib from email.mime.text import MIMEText # 导入模块 class SendEmail: def send ...
- python3发送邮件01(简单例子,不带附件)
# -*- coding:utf-8 -*-import smtplibfrom email.header import Headerfrom email.mime.text import MIMET ...
- python3发送邮件
import smtplib from email.mime.text import MIMEText from email.utils import formataddr import psutil ...
- python3 发送邮件
import smtplibfrom email.mime.text import MIMETextdef SendEmail(fromAdd,toAdd,subject,text): _pwd = ...
- python3 发送邮件功能
阿-_-涵的博客 #首先写一个模块功能,发邮件功能打包起来 from smtplib import SMTP from email.mime.text import MIMEText def send ...
- python3 发送邮件添加附件
from email.header import Headerfrom email.mime.application import MIMEApplicationfrom email.mime.mul ...
- python3发送邮件02(简单例子,带附件)
#!/usr/bin/env python# -*- coding:UTF-8 -*- import osimport smtplibfrom email.header import Headerfr ...
- Python3 SMTP发送邮件
SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. python的smtplib提供了一 ...
随机推荐
- windows 改路径有小差异
https://jingyan.baidu.com/article/5552ef473e2df6518ffbc916.html cmd是windows下一个非常常用的工具,但是它默认的地址却是不变的. ...
- CBP是什么?
coded_block_pattern 简称CBP,用来反映该宏块编码中残差情况的语法元素.CBP共有6位,其中前面2位代表UV分量,描述如下表所示:后面4位是Y分量,分别代表宏块内的4个8x8子宏 ...
- vbs 字符串替换
http://blog.csdn.net/flm2003/article/details/7212448 function返回值 http://www.cnblogs.com/wakey/p/5758 ...
- 使用vscode书写博客
很早就开始使用过vscode了,不过在已经成熟的sublime的碾压下,vscode一直没有成为我的首选,今天为了更好的博客书写体验,我直接放弃了sublime,因为 sublime对中文支持不好,而 ...
- Django实现微信公众号简单自动回复
在上篇博客阿里云部署django实现公网访问已经实现了了django在阿里云上的部署,接下来记录django实现微信公众号简单回复的开发过程,以方便日后查看 内容概要: (1)微信公众号声请 (2)微 ...
- nmap 扫描工具
Nmap 7.30 ( https://nmap.org ) 使用方法: nmap [扫描类型(s)] [选项] {目标说明}目标说明:通过主机名称, IP 地址, 网段, 等等.协议: scanme ...
- Kafka源码深度解析-序列7 -Consumer -coordinator协议与heartbeat实现原理
转自:http://blog.csdn.net/chunlongyu/article/details/52791874 单线程的consumer 在前面我们讲过,KafkaProducer是线程安全的 ...
- fn project 数据库配置
Databases We currently support the following databases and they are passed in via the DB_URL environ ...
- Verilog-2001新增特性
l generate语句 Verilog-2001添加了generate循环,允许产生 module和primitive的多个实例化,同时也可以产生多个variable,net,task,functi ...
- 获取DOS命令的返回值.
procedure CheckResult(b: Boolean); begin if not b then raise Exception.Create(SysErrorMessage(GetLas ...