Skip to main content

MailLite

PyPI version Python License Documentation Status

一款简单易用的Python邮件发送库,支持HTML模板渲染、附件发送、SSL/TLS加密连接,内置精美的邮件模板。


特性

  • 简单集成 — 几行代码即可发送邮件
  • 模板引擎 — 基于Jinja2的HTML / 纯文本模板渲染,主题(subject)也支持变量
  • 内置模板 — 开箱即用的 welcome(欢迎)和 admonition(系统通知/告警)模板
  • 自定义模板 — 支持自定义模板目录,优先级高于内置模板
  • 附件支持 — 可附加任意本地文件
  • 多种加密 — 支持 SSL(端口 465)和 STARTTLS(端口 587)
  • 完整 MIME — 纯文本、HTML、多收件人(To/CC/BCC)、Reply-To 等

安装

pip install maillite

快速开始

发送纯文本邮件

from maillite import EasyMailer

mailer = EasyMailer(
    host="smtp.qq.com",
    port=465,
    username="your@qq.com",
    password="your_auth_code",   # QQ 邮箱请使用授权码
    use_ssl=True,
)

mailer.send(
    to="test@qq.com",
    subject="测试邮件",
    body="这是一封来自 MailLite 的测试邮件。",
)

使用模板发送邮件

mailer.send_template(
    to="test@qq.com",
    subject="欢迎 {{ name }}",
    template_name="welcome",
    context={
        "name": "张三",
        "title": "欢迎加入",
        "message": "感谢您的注册!",
        "action_url": "https://example.com/dashboard",
        "action_text": "进入控制台",
    },
)

发送服务异常告警

import traceback

mailer.send_template(
    to="test@qq.com",
    subject="【{{ severity }}】{{ service_name }} 服务异常",
    template_name="admonition",
    context={
        "name": "运维同学",
        "title": "服务异常通知",
        "subtitle": "系统检测到异常,请及时关注",
        "severity": "严重",
        "service_name": "API Gateway",
        "code": "ERR_502",
        "message": "Connection refused: upstream server 10.0.0.5:8080",
        "occurred_at": "2026-07-08 20:30:00",
        "action_url": "https://monitor.example.com/incidents/123",
    },
)


try:
    a
except Exception as err:
    mailer.send_template(
    to="test@qq.com",
    subject="【{{ severity }}】{{ service_name }} 服务异常",
    template_name="admonition",
    context={
        "name": "运维同学",
        "severity": "严重",
        "service_name": "API Gateway",
        "code": "ERR_502",
        "message": traceback.format_exc(),
    },
)

API 参考

EasyMailer(...)

初始化邮件发送器。

参数 类型 默认值 说明
host str — SMTP 服务器地址
port int — SMTP 端口(SSL: 465, TLS: 587, 明文: 25)
username str — SMTP 登录用户名
password str — SMTP 登录密码 / 授权码
use_ssl bool True 使用 SSL 连接
use_tls bool False 使用 STARTTLS(不可与 use_ssl 同时开启)
default_sender str None 默认发件人地址,不填则使用 username
template_dir str None 自定义模板目录路径

mailer.send(...)

发送邮件。

参数 类型 说明
to str / list[str] 收件人
subject str 邮件主题
body str 纯文本正文
html str HTML 正文(优先于 body)
cc str / list[str] 抄送
bcc str / list[str] 密送
sender str 发件人(覆盖 default_sender)
sender_name str 发件人显示名
attachments list[str / dict] 附件列表(见下方说明)
reply_to str 回复地址

mailer.send_template(...)

使用模板发送邮件。模板通过 Jinja2 渲染,subject 同样支持模板变量。

参数 类型 说明
to str / list[str] 收件人
subject str 邮件主题(支持 Jinja2 变量)
template_name str 模板名称(不含扩展名)
context dict 模板变量字典
cc str / list[str] 抄送
bcc str / list[str] 密送
sender str 发件人
sender_name str 发件人显示名
attachments list[str / dict] 附件列表(见下方说明)
reply_to str 回复地址

attachments 附件说明

attachments 列表中的每个元素支持两种格式:

1. 文件路径(str)

attachments=["d:/report.pdf", "d:/data.xlsx"]

2. 二进制数据(dict) — 适用于动态生成的图片、文件等

attachments=[
    {
        "filename": "chart.png",
        "data": image_bytes,          # bytes 类型
        "content_type": "image/png",  # 可选,自动根据 filename 推断
    }
]

两种格式可以混合使用:attachments=["d:/report.pdf", {"filename": "chart.png", "data": image_bytes}]

如果同时存在 template_name.html 和 template_name.txt,HTML 版本作为富文本正文,TXT 版本作为纯文本备用正文。

内置模板

welcome — 欢迎模板

紫蓝渐变主题,适用于用户注册、邀请等场景。

变量 说明 默认值
title 头部标题 "欢迎使用 MailLite"
name 收件人称呼 —
message 正文内容 内置默认文案
action_url CTA 按钮链接 —
action_text CTA 按钮文案 "立即查看"
team_name 团队署名 "MailLite 团队"
help_url 底部帮助链接 —

admonition — 系统通知/告警模板

多主题告警模板,根据 severity 自动切换颜色(红/橙/绿/蓝),适用于系统监控、故障通知、服务恢复、日常通知等场景。

变量 说明 默认值
title 头部标题 "系统通知"
subtitle 头部副标题(小标题) —
name 收件人称呼 —
body 正文描述段落 —
severity 严重程度 —
service_name 服务标识 —
code 事件编号 —
message 信息内容 —
occurred_at 发生时间 自动填充当前时间(YYYY-MM-DD HH:MM:SS)
action_url 查看详情链接 —
action_text 按钮文案 "查看详情"
team_name 团队署名 "MailLite 监控团队"
help_url 底部帮助链接 —

severity 支持以下值:"严重" / "critical" (红色)、"警告" / "warning" (橙色)、"成功" / "success" (绿色)、"信息" / "info" (蓝色),其他值默认蓝色。

自定义模板

创建自己的模板目录并放置 .html / .txt 文件:

my_templates/
├── invoice.html
└── invoice.txt
mailer = EasyMailer(
    host="smtp.qq.com",
    port=465,
    username="your@qq.com",
    password="your_auth_code",
    use_ssl=True,
    template_dir="./my_templates",   # 自定义模板目录
)

mailer.send_template(
    to="test@qq.com",
    subject="发票 #{{ invoice_no }}",
    template_name="invoice",
    context={"invoice_no": "20260708-001", "amount": "¥1,280.00"},
)

自定义目录优先级高于内置模板。如果同名模板存在于两个目录,自定义版本会被使用。也可以在运行时通过 mailer._template_engine.add_template_dir(path) 动态添加模板目录。

Metadata

Release files for maillite 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for maillite 0.1.9
File
maillite-0.1.9-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
maillite-0.1.9-cp314-cp314-manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
maillite-0.1.9-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
maillite-0.1.9-cp313-cp313-manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
maillite-0.1.9-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
maillite-0.1.9-cp312-cp312-manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
maillite-0.1.9-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
maillite-0.1.9-cp311-cp311-manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
maillite-0.1.9-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
maillite-0.1.9-cp310-cp310-manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
maillite-0.1.9-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
maillite-0.1.9-cp39-cp39-manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
maillite-0.1.9-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
maillite-0.1.9-cp38-cp38-manylinux_2_17_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details

Total release size: 3.9 MB

Release files / maillite-0.1.9-cp314-cp314-win_amd64.whl

Download URL maillite-0.1.9-cp314-cp314-win_amd64.whl
Size 81.0 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
bfdbfda9e1cbcfe4457ca0d83731d067a8e6d75101747459c808a1106024b1a6
BLAKE2b-256 checksum
How to use checksums
65076a886db8990a75a0c37d93a75a63458613df743c65defdcca43280523194
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp314-cp314-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp314-cp314-manylinux_2_17_x86_64.whl
Size 475.6 kB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
62163fead3b332406f6dd7a6e34d3a9f603a3d7d7d2119700381addf18ff782b
BLAKE2b-256 checksum
How to use checksums
334550a0c41a7430dca80ed5c785cabc537cb6738adbde8425858261b55a16d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp313-cp313-win_amd64.whl

Download URL maillite-0.1.9-cp313-cp313-win_amd64.whl
Size 79.2 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c79daea8b6066ff2e98717f42e469660fccd5192ed72cc709025cc2993802bd5
BLAKE2b-256 checksum
How to use checksums
efa3dd49af7e327057e7e817dfc7f9a1742b2d55bb4203d74d27e7f99f0bcf37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp313-cp313-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp313-cp313-manylinux_2_17_x86_64.whl
Size 481.9 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
92f2b3e9a60ea93f3958443b503978e8be27491d00b6eaf4839cb8a166a5af5f
BLAKE2b-256 checksum
How to use checksums
ace9fd77a5809b7801f3746c7a70da9b0d63aec9465ac6ec06e376bf8b8cca3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp312-cp312-win_amd64.whl

Download URL maillite-0.1.9-cp312-cp312-win_amd64.whl
Size 80.3 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
bb42a1b216d7d09235e5c4512412e9be2feda9ae8b822361faa42977356a3f1f
BLAKE2b-256 checksum
How to use checksums
da8caa8291f9669a6aeaebaf73d9db5411e71ea331afb0519fa420096eac3e52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp312-cp312-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp312-cp312-manylinux_2_17_x86_64.whl
Size 494.3 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
fc9e9a97a6a7fa89fd5a155cad090774c53e17d0772c23a3595be90b638a9d70
BLAKE2b-256 checksum
How to use checksums
5380f0bcc049fa6eac02f5211c8e1500da0fab64b9c6f3a308801182a21740b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp311-cp311-win_amd64.whl

Download URL maillite-0.1.9-cp311-cp311-win_amd64.whl
Size 80.8 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
0a405eece12af7b0d68bc261f229ecd76cc0f8ace34873c047782cac03a35fe9
BLAKE2b-256 checksum
How to use checksums
af8a3e2b92ff6f7357f9c27d47bfa42c5daf553829a76395077f77c0c6ff1ddb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp311-cp311-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp311-cp311-manylinux_2_17_x86_64.whl
Size 466.2 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
829ab4a7dcdb7a54fd5f8f59e9cce1c09fdc4aab310f77a2a0eab2620ae6b84d
BLAKE2b-256 checksum
How to use checksums
00d6f0ef5580c1a4916cc1aec4b437003614fd5294c59c147d6bd8780d610fc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp310-cp310-win_amd64.whl

Download URL maillite-0.1.9-cp310-cp310-win_amd64.whl
Size 80.6 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
951096d7a4f26e56f9923038b4c9344994fe039aa00665f7a62325d9e5e7f712
BLAKE2b-256 checksum
How to use checksums
77cd7b66b06141b01aca3e768d20c70fe37147a795546ed0232abb81b7c73dff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp310-cp310-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp310-cp310-manylinux_2_17_x86_64.whl
Size 448.1 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c3c26b562b97917328c45b662ed8d27072c8df72be5855d129b0a44d2cca5828
BLAKE2b-256 checksum
How to use checksums
8b761104d3b6b12f74152b1fe939c68e0f1c2bd637b5da3c7a9c650fb72c86a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp39-cp39-win_amd64.whl

Download URL maillite-0.1.9-cp39-cp39-win_amd64.whl
Size 103.6 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
18d6830d85449857064f7fdf6b66ec947b84b2aa0fc92714f108fb5226796a68
BLAKE2b-256 checksum
How to use checksums
1147bdb083036b19814cfda5814079e4ce7ffb4a30d837aefd6eb7c90d73f734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp39-cp39-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp39-cp39-manylinux_2_17_x86_64.whl
Size 445.6 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4ba35a88e42b5660cbb764181a423337c00002c11fe3c2ea0b24245db38aaed9
BLAKE2b-256 checksum
How to use checksums
d67cce07f074d39d66bbc413ae37fce2dcec52dad2aa81ebe67b4e553f594032
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp38-cp38-win_amd64.whl

Download URL maillite-0.1.9-cp38-cp38-win_amd64.whl
Size 105.8 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
72a44c9bd31544afae2af11a8f1b57e72053001fa191fbaee7948a8b46f7e797
BLAKE2b-256 checksum
How to use checksums
4ce3a87f2a91d6179ee65d5b226f80b501732f2fe0094ca5bba9ab9fd3b91f8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Release files / maillite-0.1.9-cp38-cp38-manylinux_2_17_x86_64.whl

Download URL maillite-0.1.9-cp38-cp38-manylinux_2_17_x86_64.whl
Size 476.5 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
be37659f88bfae02d03a80f8c814ef451c7a3f3a9985bc614e9da0400e02d5ef
BLAKE2b-256 checksum
How to use checksums
c5b5837be85e60342c7b0e57ea23321c64f1708fb0edf8f686b2f8b7d6177256
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

Security for maillite 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 14 files in this release have been uploaded with provenance metadata.

Select from 14 files

Attestation for maillite-0.1.9-cp314-cp314-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.9 This release

14 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page