构建和发送电子邮件的工具

mailtools的Python项目详细描述


邮件工具

编写web应用程序?想从中发送一些电子邮件吗?Mailtools可以 救命啊!

  • Simple API for sending plain text messages, HTML and messages with attachments.
  • ^{tt1}$ sends emails in the background and returns control to your application immediately, even when talking to slow remote servers.
  • Temporary sending failures are automatically retried.
  • Running your application in test mode? The ^{tt2}$ wrapper routes emails to a test address and not to live email addresses.

用法

创建简单的SMTP邮件程序:

from mailtools import SMTPMailer
mailer = SMTPMailer('127.0.0.1')

此邮件程序将被阻止,直到邮件被发送,并且不会重试失败。使用 ThreadedMailer修复此问题:

mailer = ThreadedMailer(SMTPMailer('127.0.0.1'))

支持tls/starttls的邮件发送程序:

mailer = SMTPMailer('127.0.0.1', 465, transport_args={'security': 'TLS'})
mailer = SMTPMailer('127.0.0.1', transport_args={'security': 'STARTTLS'})

发送纯文本消息:

message = u'This is a plain text message'
mailer.send_plain(
        u'sender@example.com',
        [u'recipient@example.com'],
        u'hi',
        message
)

发送HTML消息:

message = u'<html><body>Look! HTML!</body></html>'
mailer.send_html(
        u'sender@example.com',
        [u'recipient@example.com'],
        u'hi',
        message
)

添加附件:

message = u'index.rst is attached to this message'
mailer.send_plain(
        u'sender@example.com',
        [u'recipient@example.com'],
        u'hi',
        message,
        attachments=['index.rst']
)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
是否可以将Ghost CMS与Spring Boot(Java)一起使用?如果没有,还有好的选择吗?   java简单XML框架解析器在Android中发布XML解析   java如何将数组列表设置为listview中的图像视图   java从JPA查找GUI   java为什么XSSFWorksheet的getName()不起作用?   java为什么Eclipse不记得我的启动配置?   使用java处理Json API响应   调用AlertDialog。按下后退按钮时Android片段的Java生成器   在Android中以编程方式选择项目ListView   java交错网格布局用于从实时数据库加载图像,不显示   java如何找到测试套件。Testng中的xml执行状态   java如何使用Appium通过selenium找到警报对话框?   java如何避免使用Johann的   学生编辑不起作用(Java+Spring+MySQl)?   EclipseMilo中的java身份验证clientserver   java Solr DIH获取大小无效   j_安全检查上的java筛选器不工作。Glassfish V3 Netbeans 6.8