diff --git a/README.md b/README.md index 95f07c3..216599b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Notipyer -##### Notification triggers for Python +##### Notification Triggers for Python Send async email notifications via Python. Get updates/crashlogs from your scripts with ease. ## Installation @@ -10,15 +10,19 @@ pip install notipyer ``` ## Email Notifications -Notipyer currently supports Gmail accounts as senders. To allow the library to use your gmail account, make the following changes: -1. Turn off 2-Step authentication. [Ref](https://support.google.com/accounts/answer/1064203) -2. Turn on "Less Secure App Access" [here](https://myaccount.google.com/intro/security) +Notipyer currently supports Gmail accounts as senders. To allow the library to use your Gmail account, make the following changes: + +1. Turn on 2-Step authentication. [Ref](https://support.google.com/accounts/answer/185839) +2. Create an app password. [Ref](https://support.google.com/mail/answer/185833) +3. While creating an app password, select app as "Other (Custom name)" and enter a name of your choice. +4. Use the password obtained from app password for the configuration step below. + ### Configuration ```python from notipyer.email_notify import set_email_config SENDER_EMAIL = 'myemail@gmail.com' -SENDER_PASS = 'password' +SENDER_PASS = 'my_app_password' set_email_config(SENDER_EMAIL, SENDER_PASS) ``` ### Sending Email diff --git a/notipyer/__init__.py b/notipyer/__init__.py index 8ce9b36..66a87bb 100644 --- a/notipyer/__init__.py +++ b/notipyer/__init__.py @@ -1 +1 @@ -__version__ = '0.1.3' +__version__ = '0.1.5' diff --git a/notipyer/email_notify.py b/notipyer/email_notify.py index 5551aa8..a5d0f0c 100644 --- a/notipyer/email_notify.py +++ b/notipyer/email_notify.py @@ -4,7 +4,6 @@ import smtplib SMTP_GMAIL_URL = 'smtp.gmail.com' -SMTP_GMAIL_PORT = 587 mail_cred = credentials() @@ -24,12 +23,11 @@ def set_email_config(email, password): @Async def send_email(subject, message, to_addr, cc_addr=None, bcc_addr=None): global mail_cred - global SMTP_GMAIL_URL, SMTP_GMAIL_PORT + global SMTP_GMAIL_URL to_addr, cc_addr, bcc_addr = _check_recipients(to_addr, cc_addr, bcc_addr) - client = smtplib.SMTP(SMTP_GMAIL_URL, SMTP_GMAIL_PORT) - client.starttls() + client = smtplib.SMTP_SSL(SMTP_GMAIL_URL) client = _login_client(client) recipients, email_body = _build_email(subject, message, mail_cred.EMAIL_ID, to_addr, cc_addr, bcc_addr) client.sendmail(mail_cred.EMAIL_ID, recipients, email_body) @@ -40,7 +38,7 @@ def _login_client(client): try: client.login(mail_cred.EMAIL_ID, mail_cred.EMAIL_PASS) return client - except smtplib.SMTPAuthenticationError as _: + except smtplib.SMTPAuthenticationError: raise GmailLoginException() diff --git a/setup.py b/setup.py index 51d8e95..9e3d63b 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='notipyer', version=version, - description='Notification API for Python', + description='Notification Triggers for Python', long_description=long_description, long_description_content_type="text/markdown", author='Chirag Jain', diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..f9b48b3 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +credentials.py diff --git a/tests/credentials.py.sample b/tests/credentials.py.sample new file mode 100644 index 0000000..ed30b74 --- /dev/null +++ b/tests/credentials.py.sample @@ -0,0 +1,3 @@ +username = "myemail@gmail.com" +password = "myapppassword" +target_email = "myemail@gmail.com" diff --git a/tests/test_email_send.py b/tests/test_email_send.py new file mode 100644 index 0000000..6cca5b4 --- /dev/null +++ b/tests/test_email_send.py @@ -0,0 +1,6 @@ +from credentials import * +from notipyer.email_notify import send_email, set_email_config + +set_email_config(username, password) + +send_email("my_subject", "my_content", [target_email]) \ No newline at end of file