stannp的api包装器,通过web api(如明信片和信件)发送蜗牛邮件的服务。
stannp的Python项目详细描述
AndyPi的Stannp的Python API包装器
什么是斯坦普?
Stannp允许您通过web api发送蜗牛邮件它包括 明信片和信件。有关详细信息,请参见stannp.com。
安装
pip install stannp
示例用法
初始化
导入模块并使用stannp api密钥创建实例
from stannp import StannpClient STANNP_API_KEY="XXXXXXXXXXXX" stannpinstance=StannpClient(STANNP_API_KEY)
测试发送明信片并返回json repsonse
# set recipient using a python dictionary recipient={'title': 'Mr', 'firstname':'Andy', 'lastname':'Pi', 'address1': 'My House', 'address2': 'My Town', 'city':My City', 'postcode': 'Postcode', 'country':'GB'} # Set the message text message="Hi Friend,\n\n This is a sample postcard using AndyPi's stannp-api wrapper for python" # Creates the postcard (where test.jpg is the filename of the front of the card) card=stannpinstance.send_postcard(size="A6", test=True, recipient=recipient, front="test.jpg", back=None, message=message, signature=None) # Prints the JSON repsonse from the stannp server, including the URL of a PDF preview print card
测试发送一封信并从repsonse返回pdf预览url
# set recipient using a python dictionary recipient={'title': 'Mr', 'firstname':'Andy', 'lastname':'Pi', 'address1': 'My House', 'address2': 'My Town', 'city':My City', 'postcode': 'Postcode', 'country':'GB'} # Set the message text to be a PDF named test.pdf (note the first page will have the recipients address) letter=stannpinstance.send_letter(test=True, template=None, recipient=recipient, background=None, pages="test.pdf", pdforhtml="pdf") # print the URL of the preview PDF print letter['data']['pdf']
其他
请参阅stannp.py中的注释/doctrings以了解如何 使用所有功能。