简单地发送HTML电子邮件
email-to的Python项目详细描述
发送电子邮件至
简单地发送HTML电子邮件
- 自由软件:麻省理工学院许可证
- 文档:https://email-to.readthedocs.io。
判决人:
功能
用于发送电子邮件的内置python模块功能强大,但需要很多 编写HTML格式电子邮件的样板文件。
fromemail.mime.multipartimportMIMEMultipartfromemail.mime.textimportMIMETextimportsmtplibmessage=MIMEMultipart('alternative')message['Subject']='Test'message['From']='user@gmail.com'message['To']='someone@else.com'message.attach(MIMEText('# A Heading\nSomething else in the body','plain')message.attach(MIMEText('<h1 style="color: blue">A Heading</a><p>Something else in the body</p>','html')server=smtplib.SMTP('smtp.gmail.com',587)server.starttls()server.login('user@gmail.com','password')server.sendmail('user@gmail.com','someone@else.com',message.as_string())server.quit()
使用email_to发送一封简单的电子邮件会变得更加简洁。
importemail_toserver=email_to.EmailServer('smtp.gmail.com',587,'user@gmail.com','password')server.quick_email('someone@else.com','Test',['# A Heading','Something else in the body'],style='h1 {color: blue}')
email_to还支持逐行生成消息。这是 特别适用于监视脚本,其中可能有几个不同的脚本 利益条件。
importemail_toserver=email_to.EmailServer('smtp.gmail.com',587,'user@gmail.com','password')message=server.message()message.add('# Oh boy, something went wrong!')message.add('- The server had a hiccup')message.add('- The power went out')message.add('- Blame it on a rogue backhoe')message.style='h1 { color: red}'message.send('someone@else.com','Things did not occur as expected')
另外,如果在消息开头不知道服务器的详细信息, 那也很容易处理。
importemail_tomessage=email_to.Message('# Every thing is ok')message.add('Everything has been running fine for days.')message.add('Probably time to build something new and break everything')message.style='h1 { color: green }'server=email_to.EmailServer('smtp.gmail.com',587,'user@gmail.com','password')server.send_message(message,'someone@else.com','Things are awesome')
学分
这个包是用Cookiecutter和audreyr/cookiecutter-pypackage项目模板创建的。
历史记录
0.1.0(2017-09-27)
- pypi上的第一个版本。