跳转到主要内容

使用基于Markdown或ANSI代码的内容发送邮件的Python/CLI接口

项目描述

Emili

简单的邮件发送界面。将Markdown或使用ANSI颜色的控制台输出等输入格式转换为漂亮的纯文本/HTML消息。

模块使用

import emili

content = """
# this is a title

Read **this** is very _important_!!

"""

emili.sendmail(
    from  = "me@acme.cat",
    to = [ "abe@acme.cat", "bill@acme.cat" ],
    bcc = [ "me@acme.cat" ],
    subject = "About this email"
    md = content,
    attachments = [ 'onefile.pdf' ],
	config = '../config.py',
    )

目前需要一个包含SMTP连接配置选项的config.py文件,名为smtp字典

smtp=dict(
    host='smtp.acme.cat',
    port=465,
    user='roadrunner@acme.cat',
    password='mecmec',
)

命令行使用

usage: emili.py [-h] -f SENDER -s SUBJECT -t recipient [--body TEXT]
                [--bodyfile BODYFILE] [-C CONFIG.PY] [-c CC] [-b BCC]
                [-r REPLYTO] [--format FORMAT] [--style CSSFILE]
                [--template TEMPLATE] [--dump OUTPUTFILE.eml]
                [FILE [FILE ...]]

Sends an email.

positional arguments:
  FILE                  File to attach

optional arguments:
  -h, --help            show this help message and exit
  -f SENDER, --from SENDER
                        Message sender ('From:' header)
  -s SUBJECT, --subject SUBJECT
                        Message subject ('Subject:' header)
  -t recipient, --to recipient
                        Message recipient ('To:' header) (multiple)
  --body TEXT           Message body (defaults to stdin)
  --bodyfile BODYFILE   File containing the message body (defaults to stdin)
  -C CONFIG.PY, --config CONFIG.PY
                        Python Module with smtp configuration defined.
  -c CC, --cc CC        Message copy recipient ('CC:' header) (multiple)
  -b BCC, --bcc BCC     Message hidden copy recipient ('BCC:' header)
                        (multiple), other recipients won't see this header
  -r REPLYTO, --replyto REPLYTO
                        Default address to reply at ('Reply-To:' header)
                        (multiple)
  --format FORMAT       Format for the body. 'md' takes markdown and generates
                        both html and text. 'ansi' does the same, turning ANSI
                        color codes in html or stripping them for text.
  --style CSSFILE       Style sheet for the html output, (multiple)
  --template TEMPLATE   Alternative template for the html body.
  --dump OUTPUTFILE.eml
                        Instead of sending, dump the email into a file

reportrun

usage: reportrun [-h] -s SUBJECT -t RECIPIENT [-f SENDER] [-C CONFIG.PY]
                [FILE [FILE ...]] -- COMMAND [COMMAND_ARG ...]

reportrun wraps the execution of a command and sends an email
whenever the command fails. The mail sending is processed by
emili so that ansi codes and spacing are shown properly.

positional arguments:
  FILE                  File to attach
  COMMAND               Command to run
  COMMAND_ARG           Argument for COMMAND

optional arguments:
  -f SENDER, --from SENDER
                        Message sender ('From:' header)
  -s SUBJECT, --subject SUBJECT
                        Message subject ('Subject:' header)
  -t recipient, --to recipient
                        Message recipient ('To:' header) (multiple)
  -C CONFIG.PY, --config CONFIG.PY
                        Python Module with smtp configuration defined.
  -a, --always
                        Sends even if the command does not fail.
  --
                        Marks the start of the command to execute.

变更日志

1.6 (2019-10-09)

  • 修复:reportrun忽略换行符
  • reportrun接受附件
  • reportrun --help选项,并在README中进行了文档说明

1.5 (2018-10-15)

  • 添加reportrun脚本

1.4 (2017-07-02)

  • 修复:dump不需要配置

1.3 (2016-11-02)

  • --dump选项将结果邮件作为文件输出而不是发送
  • 修复:更好地处理格式为Me <me@here.org>的地址
  • 修复:不要将完整路径作为附件名称
  • activate_wrapper.sh已移动到somenergia-utils存储库

1.2 (2016-03-28)

  • 选项-c/--config用于显式配置文件
  • 添加包装器execute_send_mail.sh
  • 添加包装器activate_wrapper.sh

1.1 (2016-01-12)

  • 在PyPi上可用

1.0 (2016-01-12)

  • 第一个版本

项目详情


下载文件

下载适合您平台文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

emili-1.6.tar.gz (6.7 kB 查看哈希值)

上传时间

由以下支持