-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
66 lines (55 loc) · 2.16 KB
/
bot.py
File metadata and controls
66 lines (55 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import smtplib
import os
import schedule
import time
from datetime import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from datetime import date
# Gmail credentials
GMAIL_USER = "ricky.email.bot@gmail.com"
GMAIL_PASSWORD = os.getenv("GMAIL_PASSWORD")
TO_EMAILS = ["rickylin543@gmail.com", "ricky.lin1@motorolasolutions.com"]
SUBJECT = "GO AND DO YOUR TIMESHEET"
BODY = """
<p>Don't forget about your timesheets, buddy! ⏳</p>
<p><a href="https://workforcenow.adp.com/theme/index.html#/Myself/MyselfTabTimecardsAttendanceSchCategoryTLMWebMyTimecard" target="_blank">Click here to submit your timesheet</a></p>
"""
LAST_SENT_DATE = None
def send_email():
global LAST_SENT_DATE
today = date.today()
# Only send email if 14 days have passed since the last email
if LAST_SENT_DATE is None or (today - LAST_SENT_DATE).days >= 13:
try:
# Set up email
msg = MIMEMultipart()
msg["From"] = GMAIL_USER
msg["To"] = ", ".join(TO_EMAILS) # ✅ Set all recipients at once
msg["Subject"] = SUBJECT
msg.attach(MIMEText(BODY, "html"))
# Connect to Gmail SMTP server
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(GMAIL_USER, GMAIL_PASSWORD)
# Send email once to all recipients
server.sendmail(GMAIL_USER, TO_EMAILS, msg.as_string())
print(f"✅ Email sent successfully to {', '.join(TO_EMAILS)} on {today}")
# Close server
server.quit()
# Update last sent date
LAST_SENT_DATE = today
except Exception as e:
print(f"❌ Error: {e}")
# Schedule to check every Friday at 10 AM
schedule.every().friday.at("10:00").do(send_email)
send_email()
# Schedule the email every Friday at 10 AM
schedule.every().friday.at("10:00").do(send_email)
print("📅 Scheduler started! Waiting for the next scheduled email...")
# Keep the script running
while True:
schedule.run_pending()
time.sleep(60) # Check every minute