|
@@ -23,19 +23,19 @@ or styling in general. Here is a comparison
|
|
|
of using ``df.to_html()`` directly vs embedding
|
|
of using ``df.to_html()`` directly vs embedding
|
|
|
via Red Mail:
|
|
via Red Mail:
|
|
|
|
|
|
|
|
-|pic1| -- |pic2|
|
|
|
|
|
|
|
+|pic1| vs |pic2|
|
|
|
|
|
|
|
|
-.. |pic1| image:: /imgs/table_unrendered.png
|
|
|
|
|
|
|
+.. |pic1| image:: /imgs/table_without_style.png
|
|
|
:height: 150px
|
|
:height: 150px
|
|
|
:align: top
|
|
:align: top
|
|
|
|
|
|
|
|
|
|
|
|
|
-.. |pic2| image:: /imgs/table_rendered.png
|
|
|
|
|
|
|
+.. |pic2| image:: /imgs/table_with_style.png
|
|
|
:height: 150px
|
|
:height: 150px
|
|
|
:align: top
|
|
:align: top
|
|
|
|
|
|
|
|
|
|
|
|
|
-To embed tables, you can si mply pass them
|
|
|
|
|
|
|
+To embed tables, you can simply pass them
|
|
|
to the send function as Pandas dataframes:
|
|
to the send function as Pandas dataframes:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
.. code-block:: python
|
|
@@ -68,7 +68,23 @@ well CSS.
|
|
|
dataframe strucutres (empty, multi-indexed etc.) but
|
|
dataframe strucutres (empty, multi-indexed etc.) but
|
|
|
sometimes the rendering may be off if the dataframe
|
|
sometimes the rendering may be off if the dataframe
|
|
|
is especially complex in structural sense. There are
|
|
is especially complex in structural sense. There are
|
|
|
- development plans to make it even more better.
|
|
|
|
|
|
|
+ plans to make it even more better.
|
|
|
|
|
+
|
|
|
|
|
+You may also override the template paths (see
|
|
|
|
|
+:ref:`templating`) to create custom templates
|
|
|
|
|
+if you wish to make your own table prettifying:
|
|
|
|
|
+
|
|
|
|
|
+.. code-block:: python
|
|
|
|
|
+
|
|
|
|
|
+ email.set_template_paths(
|
|
|
|
|
+ html_table="path/to/templates",
|
|
|
|
|
+ text_template="path/to/templates"
|
|
|
|
|
+ )
|
|
|
|
|
+ email.default_html_theme = "my_table_template.html"
|
|
|
|
|
+ email.default_text_theme = "my_table_template.txt"
|
|
|
|
|
+
|
|
|
|
|
+The templates get parameter ``df`` which is the dataframe
|
|
|
|
|
+to be prettified.
|
|
|
|
|
|
|
|
.. _embedding-images:
|
|
.. _embedding-images:
|
|
|
|
|
|
|
@@ -83,12 +99,19 @@ of the email:
|
|
|
email.send(
|
|
email.send(
|
|
|
subject='Some attachments',
|
|
subject='Some attachments',
|
|
|
receivers=['first.last@example.com'],
|
|
receivers=['first.last@example.com'],
|
|
|
- html="<h1>This is an image:</h1> {{ myimage }}",
|
|
|
|
|
|
|
+ html="""<h1>This is an image:</h1>
|
|
|
|
|
+ {{ my_image }}
|
|
|
|
|
+ """,
|
|
|
body_images={
|
|
body_images={
|
|
|
- 'myimage': 'path/to/image.png',
|
|
|
|
|
|
|
+ 'my_image': 'path/to/image.png',
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+The outcome looks like this:
|
|
|
|
|
+
|
|
|
|
|
+.. image:: /imgs/email_emb_img.png
|
|
|
|
|
+ :align: center
|
|
|
|
|
+
|
|
|
The image will be rendered as ``<img src="cid:...">``.
|
|
The image will be rendered as ``<img src="cid:...">``.
|
|
|
In case you need to control the image (like the size)
|
|
In case you need to control the image (like the size)
|
|
|
you can also create the ``img`` tag yourself:
|
|
you can also create the ``img`` tag yourself:
|
|
@@ -98,9 +121,9 @@ you can also create the ``img`` tag yourself:
|
|
|
email.send(
|
|
email.send(
|
|
|
subject='Some attachments',
|
|
subject='Some attachments',
|
|
|
receivers=['first.last@example.com'],
|
|
receivers=['first.last@example.com'],
|
|
|
- html='<h1>This is an image:</h1> <img src="{{ myimage.src }}">',
|
|
|
|
|
|
|
+ html='<h1>This is an image:</h1> <img src="{{ my_image.src }}" width=500 height=350>',
|
|
|
body_images={
|
|
body_images={
|
|
|
- 'myimage': 'path/to/image.png',
|
|
|
|
|
|
|
+ 'my_image': 'path/to/image.png',
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -110,3 +133,37 @@ In addition to paths as strings, the following are supported:
|
|
|
- ``bytes`` (the image as raw bytes)
|
|
- ``bytes`` (the image as raw bytes)
|
|
|
- ``matplotlib.pyplot.Figure``
|
|
- ``matplotlib.pyplot.Figure``
|
|
|
- ``PIL.Image``
|
|
- ``PIL.Image``
|
|
|
|
|
+
|
|
|
|
|
+.. _embedding-plt:
|
|
|
|
|
+
|
|
|
|
|
+Embedding Figure
|
|
|
|
|
+^^^^^^^^^^^^^^^^
|
|
|
|
|
+
|
|
|
|
|
+As mentioned, you may also include Matplotlib figures directly to the email.
|
|
|
|
|
+This is especially handy if you are creating automatic statistics.
|
|
|
|
|
+
|
|
|
|
|
+A simple example to include a figure:
|
|
|
|
|
+
|
|
|
|
|
+.. code-block:: python
|
|
|
|
|
+
|
|
|
|
|
+ # Create a simple plot
|
|
|
|
|
+ import matplotlib.pyplot as plt
|
|
|
|
|
+ fig = plt.figure()
|
|
|
|
|
+ plt.plot([1,2,3,2,3])
|
|
|
|
|
+
|
|
|
|
|
+ # Send the plot
|
|
|
|
|
+ email.send(
|
|
|
|
|
+ subject='Some attachments',
|
|
|
|
|
+ receivers=['first.last@example.com'],
|
|
|
|
|
+ html="""<h1>This is a plot:</h1>
|
|
|
|
|
+ {{ my_plot }}
|
|
|
|
|
+ """,
|
|
|
|
|
+ body_images={
|
|
|
|
|
+ 'my_plot': fig,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+The outcome looks like this:
|
|
|
|
|
+
|
|
|
|
|
+.. image:: /imgs/email_emb_plt.png
|
|
|
|
|
+ :align: center
|