day06-发送邮件

一、发送邮件

import yagmail
# 账号  密码  邮箱服务器  发给人  抄送人  主题  正文  附件

username = '[email protected]'
passwd = '*******'#密码是SMTP中显示的授权码
mail = yagmail.SMTP(user=username,password=passwd,host='smtp.qq.com',
             smtp_ssl=True)
# 连接上邮箱
mail.send(to='1936790***@qq.com',subject='有好吃的',
          contents='不给你吃',attachments=r'C:\Users\Administrator.PC-201703021544\Desktop\linux常用操作命令.doc')
# qq邮箱需要添加smtp_ssl,是安全协议
# cc='[email protected]',抄送给谁
# to发送给谁
# subject主题是什么
# contents正文是什么
# 发送给多个人用list,to = ['1936798****@qq.com','133498****@qq.com']
# 抄送给多个人用list,cc = ['193****[email protected]','13349****@qq.com']
# attachments='C:\Users\Administrator.PC-201703021544\Desktop\linux常用操作命令.doc',附件名字为中文


# 如果发送的附件名,中文是乱码的话
# pip uninstall yagmail,先把pip安装的卸载掉
# 然后用群里给的yagmail....whl

二、qq邮箱开启SMTP服务

示例如下:

猜你喜欢

转载自www.cnblogs.com/Noul/p/9294166.html