.. _cookbook: Cookbook ========= This section provides various examples for various needs. .. _cookbook-campaign: Email Campaign -------------- In case you have a list of clients or customers you wish to send personalized emails, you may benefit from templating. It may help to make the templates to an HTML file, polish them and after then send: .. code-block:: python from redmail import EmailSender email = EmailSender(...) email.receivers = ['we@example.com'] email.set_template_paths( html="path/to/campaigns" ) Then make a HTML file, for example ``path/to/campaigns/summer_sale.html``: .. code-block:: html
We are pleased to inform you that we have a lot of products in huge discounts.
Kind regards, We Ltd.
Finally send the emails: .. code-block:: python discounts = {'shoes': 0.2, 'shirts': 0.4} customers = ['cust1@example.com', 'cust2@example.com', ...] for customer in customers: email.send( subject="Summer Sale!", html_template="summer_sale.html", body_params={ "customer": customer, "discounts": discounts } ) .. _cookbook-alerts: Error Alerts ------------ If you are building long running program (ie. web app) you can make a templated error alerts that include the full traceback: .. code-block:: python from redmail import EmailSender error_email = EmailSender(...) error_email.sender = 'me@example.com' error_email.receivers = ['me@example.com'] error_email.html = """System running on {{ node }}
""", body_images={ "perf_plot": fig_performance, }, body_tables={ "tbl_summary": df_summary } )