python实现邮件发送图表_CTEmail 是一个发送带有图表邮件的简单粗暴的Python脚本...

Interduction

CTEmail is a Charts and Text Email script, which can send email with chart pictures in email content body not email attachment.

Why make this tool?

As a programmer, we hope to complete everything automatically by scripts, such as send report email daily.

In business, we cooperate with some friends. Sometimes we exchange the report with data, where we can use charts and suitable text to display.

We can find some pictures in some emails, but those pictures are manual and the email is also manual.

These are all things that we needs.

Who can use it?

Product manager, CTEmail is one of the best practices!

Operating Officer, CTEmail is one of the best practices!

Programmer, everything is automated!

Requirement

Python:Python2(You can also use Python3 with similar code!)

PlotlyA tool for displaying your data. It supports offline and online modes. You can read the documents from the website.

Project structure

├── README.md

├── content

│   ├── image1.png

│   ├── image2.png

│   └── index.html

├── ctemail.py

├── get_img.py

└── send.py

Under the content folder, you will see the index.html file, which is the content of email. Also this folder include the images(charts) resources.

ctemail.py is the CTEmail class written by Python script.

send.py is the script to send email and configures of email account.

get_img.py can generate the chart images by plotly.

Installation

First Step:

git clone git@github.com:dyike/CTEmail.git

Second Step:

Config the send email scprit:

from ctemail import CTEmail

e = CTEmail('Your email acount', 'Your password')

# " ./content/ " is the email path

e.send_email('Test Email', './content/', ['i@ityike.com'])

Third Step:

Deal with the data, then generate the chart images.

Also we can add some code to generate the conten/index.html file.

Here is a demo:

import plotly.plotly as py

import plotly.graph_objs as go

py.sign_in('Your account', 'API Token') # Configure your username and api key token

trace = go.Bar(x=[2, 4, 6], y= [10, 12, 15])

data = [trace]

layout = go.Layout(title='A Simple Plot', width=800, height=640)

fig = go.Figure(data=data, layout=layout)

py.image.save_as(fig, filename='./content/image.png')

Fourth Step:

In the email template file, you will see the tag. It is essential! The script will find the tag to parse. If you want to add two or more images, you should do as follows:

image1.png

image2.png

Fifth Step:

Send email!

python send.py

then, you will received email!

2f3dc38fc0a43579348437bde0c0d763.png

LICENSE

MIT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值