Skip to content

Commit 95913af

Browse files
committed
add async optional support
1 parent 56658af commit 95913af

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ to_recipients = ['[email protected]', '[email protected]'] # Can be None
3737
cc_recipients = ['[email protected]', '[email protected]'] # Can be None
3838
bcc_recipients = ['[email protected]', '[email protected]'] # Can be None
3939
attachment_path = 'path_to_my_file' # Can be None
40+
is_async = True # Sent as an async email only if this parameter is True
4041

41-
send_email(subject, body, to_recipients, cc_recipients, bcc_recipients, attachment_path)
42+
send_email(subject, body, to_recipients, cc_recipients, bcc_recipients, attachment_path, is_async)
4243
```
4344

4445
## Slack Notifications

notipyer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .credential_handler import credentials
22

3-
__version__ = '0.3.1'
3+
__version__ = '0.3.2'
44
__name__ = 'Notipyer'
55
__short_desc__ = 'Notification Triggers for Python'
66
__url__ = 'https://github.com/chirag-jn/notipyer'

notipyer/email_notify.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def set_email_config(email, password, sender_name=''):
2727
_set_email_credentials(mail_cred, email, password, sender_name)
2828

2929

30-
@Async
31-
def send_email(subject, message, to_addr=None, cc_addr=None, bcc_addr=None, attachment_path=None):
30+
def _send_email_helper(subject, message, to_addr=None, cc_addr=None, bcc_addr=None, attachment_path=None):
3231
global mail_cred
3332
global SMTP_GMAIL_URL
3433

@@ -39,6 +38,15 @@ def send_email(subject, message, to_addr=None, cc_addr=None, bcc_addr=None, atta
3938
recipients, email_body = _build_email(subject, message, to_addr, cc_addr, bcc_addr, attachment_path)
4039
client.sendmail(mail_cred.EMAIL_ID, recipients, email_body)
4140
client.quit()
41+
return True
42+
43+
44+
def send_email(subject, message, to_addr=None, cc_addr=None, bcc_addr=None, attachment_path=None, is_async=True):
45+
global _send_email_helper
46+
if is_async:
47+
_send_email_helper = Async(_send_email_helper)
48+
49+
return _send_email_helper(subject, message, to_addr, cc_addr, bcc_addr, attachment_path)
4250

4351

4452
def _login_client(client):

tests/test_email_send.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
set_email_config(username, password, name)
55

6-
send_email("my_subject", "my_content", [target_email], attachment_path='credentials.py.sample')
6+
print(send_email("my_subject", "my_content", [target_email], attachment_path='credentials.py.sample', is_async=True))
7+
print('Email Sent')

0 commit comments

Comments
 (0)