Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nfultz/nb2mail
Send a notebook as an email
https://github.com/nfultz/nb2mail
jupyter-notebook post-processor smtp
Last synced: 7 days ago
JSON representation
Send a notebook as an email
- Host: GitHub
- URL: https://github.com/nfultz/nb2mail
- Owner: nfultz
- Created: 2016-08-28T23:42:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-06T17:40:48.000Z (12 months ago)
- Last Synced: 2024-05-01T13:50:51.539Z (8 months ago)
- Topics: jupyter-notebook, post-processor, smtp
- Language: Python
- Size: 47.9 KB
- Stars: 138
- Watchers: 15
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nb2mail - send a jupyter notebook as an email
[![PyPI version](https://badge.fury.io/py/nb2mail.svg)](https://badge.fury.io/py/nb2mail)
This repo contains a `jupyter nbconvert` exporter to convert notebooks to multipart MIME, and a postprocessor to
send it via smtp.## Installation
pip install nb2mail
## Usage
`nb2mail` does not do anything by itself. It provides an export format
("mail") and postprocessor ("SendMailPostProcessor"). Please see the nbconvert
documentation and example configuration for more information.## Example
To generate a mail and send it later with another process (eg `sendmail`):
jupyter nbconvert --execute --to mail notebook.ipynb
### SMTP Example
To convert and send a mail via gmail, you can set the environment
variables and declare a postprocessor with `--post`:export [email protected] GMAIL_USER=user GMAIL_PASS="*****"
jupyter nbconvert --to mail --post=nb2mail.SendMailPostProcessor notebook.ipynbAlternatively, you can configure the SMTP settings in a config file `config.py`:
c = get_config()
c.NbConvertApp.export_format = 'mail'
c.Exporter.preprocessors = 'nbconvert.preprocessors.ExecutePreprocessor'
c.NbConvertApp.postprocessor_class = 'nb2mail.SendMailPostProcessor'
c.SendMailPostProcessor.recipient = '[email protected]'
c.SendMailPostProcessor.smtp_user = 'user'
c.SendMailPostProcessor.smtp_pass = '*******'
c.SendMailPostProcessor.smtp_addr = 'smtp.gmail.com'
c.SendMailPostProcessor.smtp_port = 587and then run:
jupyter nbconvert --config config.py demo.ipynb
### 3rd party email distributor Example
Instead of using SMTP to send emails, one can use 3rd party provider.
This is an example for using [mailgun](examples/mailgun.ipynb) as a 3rd party provider## Configuring Mail Headers
In the notebook metadata, you can set mail headers by adding a `nb2mail` block:
"nb2mail": {
"attachments": [
"business_report_attachment.xlsx"
],
"From": "[email protected]",
"To": "[email protected], [email protected]",
"Subject": "Business Report"
}You can specify multiple recipients by seperating them with commas.
## Disabling Pilcrows
Since CSS doesn't render the same in email, you may want to disable the pilcrows after each section.
c.MailExporter.anchor_link_text = '' # disable pilcrow, requires nbconvert >= 5.2
## Refences
* PyPI - https://pypi.python.org/pypi/nb2mail
## TODO
* Prerender Math - no js in email
* Prettier templates
* Plotly - here is a workaround:# py.iplot(fig, filename=‘dcm_ctr_subplots’)
# The above line is what you normally use to show your plots in the notebook
# You no longer need that and just need the stuff belowfrom IPython.display import Image
py.image.save_as(fig, filename='yahoo_dcm_ctr_subplots.png')
Image('yahoo_dcm_ctr_subplots.png')