-
Notifications
You must be signed in to change notification settings - Fork 5
/
scheduled_emails.py
34 lines (30 loc) · 1.17 KB
/
scheduled_emails.py
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
import os
import time
from selenium import webdriver
email = os.environ.get("EMAIL")
password = os.environ.get("EMAIL_PASSWORD")
recipient_email = "recipient@example.com"
email_subject = "Scheduled Email"
email_message = "This is a scheduled email sent using Selenium."
def send_email():
driver = webdriver.Chrome()
driver.get("https://mail.google.com")
driver.find_element_by_id("identifierId").send_keys(email)
driver.find_element_by_id("identifierNext").click()
time.sleep(2)
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_id("passwordNext").click()
time.sleep(2)
driver.find_element_by_xpath("//div[text()='Compose']").click()
driver.find_element_by_name("to").send_keys(recipient_email)
driver.find_element_by_name("subjectbox").send_keys(email_subject)
driver.find_element_by_xpath("//div[@aria-label='Message Body']").send_keys(email_message)
driver.find_element_by_xpath("//div[contains(text(),'Send')]").click()
driver.quit()
scheduled_time = "10:00"
while True:
current_time = time.strftime("%H:%M")
if current_time == scheduled_time:
send_email()
break
time.sleep(60)