邮件
封装简单的邮件推送功能,支持发送单个或多个收件/抄送人,支持附件上传
项目结构
- easy-email
- LISENCE.md
- README.md
- setup.py
- src
- __init__.py
- easy_email.py
- tests
- conf
- email_conf.yml
- column_config.yml
- template
- template.html
- __init__.py
- example.py
- table_example.py
- test_class.py
- conf
使用方法
安装/更新
pip install dm-easy-email # 安装
pip install dm-easy-email --upgrade # 更新
配置文件模板
模板1--邮件发送
sender:
xxx@example.com
passwd:
your_passwd
receiver:
- aaa@example.com
- bbb@example.com
subject:
your_title
# Params below could be None
nickname:
your_nickname
cc:
ccc@example.com
模板2--html列表配置参数
- column_code: a
column_name: a
align: center
unit: '%'
width: 50px
- column_code: b
column_name: b
align: center
unit: ''
width: 150px
- column_code: c
column_name: c
align: center
unit: ''
width: 100px
- column_code: d
column_name: d
align: center
unit: '%'
width: 50px
示例1(body_type='plain')
from easy_email.easy_email import EasyEmail
from ruamel import yaml
import os
if __name__ == '__main__':
print(os.getcwd())
with open('conf/email.yml', 'r') as f:
content = yaml.load(f, Loader=yaml.Loader)
sender = content['sender']
receiver = content['receiver']
subject = content['subject']
nickname = content['nickname']
# file_path = 'conf/email.yml'
passwd = content['passwd']
cc = content['cc']
email = EasyEmail(
sender=sender, passwd=passwd,
subject=subject, nickname=nickname,
receiver=receiver, cc=cc
)
body = 'Hello world'
email.send(body)
示例2(body_type='html')
from easy_email.easy_email import EasyEmail
from ruamel import yaml
import pandas as pd
import string
if __name__ == '__main__':
with open('conf/email_conf.yml', 'r') as f:
content = yaml.load(f, Loader=yaml.Loader)
with open('conf/column_config.yml', 'r') as f_config:
column_config = yaml.load(f_config, Loader=yaml.Loader)
df = pd.DataFrame(
{'a': [i for i in range(10)],
'b': ['a' for _ in range(10)],
'c': ['hello' for _ in range(10)],
'd': [i for i in range(10, 20)]}
)
df.to_csv('data/data.csv', index=None)
sender = content['sender']
receiver = content['receiver']
subject = content['subject']
nickname = content['nickname']
file_path = 'data/data.csv'
passwd = content['passwd']
email = EasyEmail(
sender=sender, passwd=passwd,
subject=subject, nickname=nickname,
receiver=receiver,
file_path=file_path
)
emo = {
'col': ['a', 'd'],
'threshold': 16,
'is_upper': True
}
table_html = email.table_to_html(
df=df,
column_config=column_config,
sort={'var': ['a', 'd'], 'ascending': False},
row_limit=30,
emo=emo
)
template_html = open('template/template.html', encoding='utf8').read()
body = string.Template(template_html).safe_substitute(
{
'task1': table_html
}
)
email.send(body, 'html')
多附件说明
如需多附件,使用如下形式定义file_path参数即可。
file_path = ["path1/file_name1", "path2/file_name2", ...]
开发日志
2022-2-17 # v0.1.0
- 完成邮件推送功能开发与测试,并推至仓库
- 完成打包并发布到pypi
2022-2-28 # v0.1.1
- 调整邮件发送类型,支持html
2022-3-2 # v0.2.0
- 新增dataframe转化html功能
- 补充dataframe转化示例
2022-3-4 # v0.2.1
- 支持多附件上传
2022-3-15 # v0.2.2
- 调整参数类型,修复linux环境报错
Metadata
Release files for dm-easy-email 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dm-easy-email-0.2.3.tar.gz | 8.2 kB | Without provenance | Details for dm-easy-email-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dm_easy_email-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for dm_easy_email-0.2.3-py3-none-any.whl |
Total release size: 17.1 kB
Release files / dm-easy-email-0.2.3.tar.gz
| Download URL | dm-easy-email-0.2.3.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb9cb316215b234798f60b38f697bf0462b59a7b28cf8be81829516ecacd8b7b
|
|
BLAKE2b-256 checksum How to use checksums |
297ea7f43b2c41fd948eceb1aa26f0cde190b364b9b1380ba6b7cebc9019f381
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Release files / dm_easy_email-0.2.3-py3-none-any.whl
| Download URL | dm_easy_email-0.2.3-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0a91485e74bc91b9fa2ec499d590cb49976d9d1f08403e40a71b03b7b710f6a
|
|
BLAKE2b-256 checksum How to use checksums |
5db1a294c8134b4905812c5273535f66156325dfbb96b709b95a53e1f57dcc11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
|
Security for dm-easy-email 0.2.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.