yagmail邮件模块

昨天接到一个需求,就是要求用邮件发送一html文件。这里我想到了用yagmail

#!/usr/bin/env python
#-*- coding:utf-8 -*-  
import yagmail
import requests
import urllib.request   #py3中urllib2改成了urllib.requests
import os
yag = yagmail.SMTP(user='[email protected]',password='wuXXXXX',host='smtp.163.com',port='465')
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
body = r.json()['note']

image = r.json()['fenxiang_img']
name = image.split('/')[-1]
print(body)


s = urllib.request.urlretrieve(image,r'H://py1//%s'%name)

#yag.send(to='[email protected]', subject='测试邮件', contents=[body,'深圳政府采购接口测试.py'])
jpg_path = 'H://py1//%s'%name

try:
	yag.send(to=['[email protected]','[email protected]'], subject='一封特殊的邮件', contents=[body,jpg_path])
except Exception as e:
	print(e)
else:
	print('邮件发送成功')
finally:
	print('程序已执行')

  

其实内置的邮件模块 stamp也是可以的,但是又好用的yagmail 包,为什么不用呢。毕竟

人生苦短  我用python  哈哈。

转载于:https://www.cnblogs.com/wujf-myblog/p/11082884.html

你可能感兴趣的:(yagmail邮件模块)