diff --git a/README.md b/README.md index 5e21155..fce9d97 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ send it via smtp. ## Installation - pip install nb2mail + pip install git+https://github.com/Thessal/nb2mail.git ## Usage @@ -15,6 +15,8 @@ send it via smtp. ("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`): @@ -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`: diff --git a/nb2mail/__init__.py b/nb2mail/__init__.py index 61a8807..7a3a513 100644 --- a/nb2mail/__init__.py +++ b/nb2mail/__init__.py @@ -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) @@ -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()