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

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第三方库


热门话题
java使用双一元运算符vs函数<Double,Double>   由于存在巨大的休眠,超出了java GC开销限制   java更改Tomcat中Apache文件上载的临时目录   当PDF位于本地驱动器时,javascript无法在IE中显示PDF   java hibernate如何加载瞬态对象?   java如何判断包属于哪个模块?   创建Word文档时java文件已损坏   java如何将Eclipse中的每个开放项目导出为自己的JAR?   java将带有getter和setter的变量添加到现有类中   java高效地发送多封电子邮件   java读/写。具有特殊字符的txt文件   java如何在导出到jar时包含opencv本机库   java Xstream在未完成时停止写入文件   if语句Java:无法检查布尔值是否为null   文本Java:读取txt文件并将其保存在字符串数组中,但不带反斜杠(空格)?   java如何使用正则表达式替换字符串的一部分   通过Java远程运行Powershell脚本   filenames带有xml文件空指针异常的Java文件uri