Python

使用yagmail 发邮件

2020-01-08  本文已影响0人  朝畫夕拾

使用yagmail之前需要先安装yagmail模块,安装命令如下:

pip3  install   yagmail

下面是requests用法介绍

import  yagmail   #邮箱的账号密码、腾讯邮箱  #给谁发邮件、抄送给谁#邮件的主题、邮件的正文、附件

user ='test@163.com'

passwd ='hxxx'#授权码

smtp_host ='smtp.163.com'

# smtp_host ='smtp.qq.com'

mail = yagmail.SMTP(user=user,password=passwd,host=smtp_host)#连上邮箱

mail.send(to=['xx@qq.com','111@qq.com','123@qq.com'],          

cc=['asdf@qq.com','asdf@163.com','bsdf@qq.com'],          

subject='明天好好在家休息',          

contents='明天多吃点,吃的饱饱的,在家睡个懒觉',          

attachments=['app_myuser.xls','CJ_test.xls']          )

收件人和抄送人都可以使用列表,这样可以同时发送给多个邮箱。

----------------------------------------------------------------------------------------------------

import   yagmail 

 yag = yagmail.SMTP(user='user@163.com',password='1234',host='smtp.163.com')

contents= ['这里是内容'] 

 yag.send('target@qq.com','主题:这是一个主题',contents)

上一篇下一篇

猜你喜欢

热点阅读