Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ send it via smtp.

## Installation

pip install nb2mail
pip install git+https://github.com/Thessal/nb2mail.git

## 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.

NOTE: BOTH sender and recipient email identities have to be verified to use AWS SES SMTP

## Example

To generate a mail and send it later with another process (eg `sendmail`):
Expand All @@ -25,7 +27,9 @@ To generate a mail and send it later with another process (eg `sendmail`):
To convert and send a mail via gmail, you can set the environment
variables and declare a postprocessor with `--post`:

export TO=example@example.ex GMAIL_USER=user GMAIL_PASS="*****"
export FROM=sender@domain.abc TO=receipent@domain.def
export SMTP_ADDR=email-smtp.region.amazonaws.com SMTP_PORT=587
export SMTP_USER=aws_ses_smtp_auth SMTP_PASS=`echo $SMTP_HASH | base64 -d`
jupyter nbconvert --to mail --post=nb2mail.SendMailPostProcessor notebook.ipynb

Alternatively, you can configure the SMTP settings in a config file `config.py`:
Expand Down
14 changes: 8 additions & 6 deletions nb2mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ def from_notebook_node(self, nb, resources=None, **kw):

class SendMailPostProcessor(PostProcessorBase):

sender = Unicode(os.getenv("FROM", ''), help="Sender address").tag(config=True)
recipient = Unicode(os.getenv("TO", ''), help="Recipient address").tag(config=True)
smtp_user = Unicode(os.getenv("GMAIL_USER", ''), help="SMTP User" ).tag(config=True)
smtp_pass = Unicode(os.getenv("GMAIL_PASS", ''), help="SMTP pass" ).tag(config=True)
smtp_addr = Unicode("smtp.gmail.com", help="SMTP addr" ).tag(config=True)
smtp_port = Int(587, help="SMTP port" ).tag(config=True)

smtp_user = Unicode(os.getenv("SMTP_USER", ''), help="SMTP User" ).tag(config=True)
smtp_pass = Unicode(os.getenv("SMTP_PASS", ''), help="SMTP pass" ).tag(config=True)
smtp_addr = Unicode(os.getenv("SMTP_ADDR", ''), help="SMTP addr" ).tag(config=True)
smtp_port = Int(os.getenv("SMTP_PORT", '587'), help="SMTP port" ).tag(config=True)
smtp_port = smtp_port.default_value

def postprocess(self, input):
" Heavily borrowed from https://www.mkyong.com/python/how-do-send-email-in-python-via-smtplib/ "
smtpserver = smtplib.SMTP(self.smtp_addr,self.smtp_port)
Expand All @@ -180,6 +182,6 @@ def postprocess(self, input):
# Set To header from config
email['To'] = self.recipient

smtpserver.sendmail(self.smtp_user, self.recipient.split(','), email.as_string())
smtpserver.sendmail(self.sender, self.recipient.split(','), email.as_string())

smtpserver.close()