.. _examples-simple: Examples ======== Simple Example -------------- .. code-block:: python from redmail import EmailSender email = EmailSender( host='localhost', port=0, user_name='me@example.com', password='' ) email.send( subject="An email", sender="me@example.com", receivers=['you@example.com'], test="Hi, this is an email.", html="

Hi,

this is an email.

" ) .. _examples-mega: Super Example ------------- This example covers the most interesting features of Red Mail: .. code-block:: python from pathlib import Path from redmail import EmailSender import pandas as pd from PIL import Image import matplotlib.pyplot as plt fig = plt.figure() plt.plot([1, 2, 3]) df = pd.DataFrame({"A": [1, 2, 3], "B": [1, 2, 3]}) byte_content = Path("a_file.bin").read_bytes() email = EmailSender( host='localhost', port=0, user_name='me@example.com', password='' ) # Send an email email.send( subject="A lot of stuff!", sender="me@example.com", # Receivers receivers=["you@example.com"], cc=['also@example.com'], bcc=['external@example.com'], # Bodies text="""Hi {{ friend }}, This email has a lot of stuff! Use HTML to view the awesome content. """, html="""

Hi {{ friend }},

This email has a lot of stuff!

Like this image:

{{ my_image }}

or this image:

{{ my_pillow }}

or this plot:

{{ my_plot }}

or this table:

{{ my_table }}

or this loop:

""", # Embedded content body_images={ "my_image": "path/to/image.png", "my_pillow": Image.new('RGB', (100, 30), color = (73, 109, 137)) "my_plot": fig, }, body_tables={ "my_table": df, }, body_params={ "friend": "Jack", "container": [1, 3, 5, 7, 9], }, attachments={ "data.csv": df, "file.txt": "This is file content", "file.html": Path("path/to/a_file.html"), "file.bin": byte_content, } )