Skip to content

Commit e6db181

Browse files
committed
conditional recepients
1 parent ee063f4 commit e6db181

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

examples/conditional.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
import os
23
from dotenv import load_dotenv
34
import redmail
@@ -50,14 +51,26 @@
5051

5152
email_body = intro + table_html + salutation
5253

54+
today = datetime.today()
55+
is_weekday = today.weekday() < 5 # Monday=0, ..., Friday=4
56+
is_monday = today.weekday() == 0
57+
5358
# This is here to emphasize the sender does not have to be the same as the receiver
54-
email_receiver = gmail_address
59+
# and the receiver list can vary
60+
if is_weekday:
61+
if is_monday:
62+
email_receivers = [gmail_address, gmail_address, gmail_address]
63+
else:
64+
email_receivers = [gmail_address, gmail_address]
65+
else:
66+
email_receivers = [gmail_address]
67+
5568

5669
redmail.gmail.username = gmail_address
5770
redmail.gmail.password = gmail_app_password
5871

5972
redmail.gmail.send(
6073
subject=email_subject,
61-
receivers=["jules.walzergoldfeld@posit.co"],
74+
receivers=email_receivers,
6275
html=email_body,
6376
)

0 commit comments

Comments
 (0)