Algorithms
Objective: Write a python script to automate the daily sending of email messages. The script should generate a daily message and send it via email.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import schedule
import time
# Function to send email
def send_email(subject, body, to_email):
# email credentials
sender_email = "#for security reasons this will be hidden"
sender_password = "#for security reasons this will be hidden"
# Create message
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = to_email
message["Subject"] = subject
message.attach(MIMEText(body, "plain"))
# Connect to the SMTP server (Gmail in this case)
with smtplib.SMTP("smtp.gmail.com", 587) as server:
server.starttls()
server.login(sender_email, sender_password)
server.send_message(message)
# Function to generate daily report
def generate_d
aily_report():
aily_report():
report_content = "#personal message of choice"
# Send the email
send_email("Daily Report", report_content, "#for security reasons this will be
hidden")
# Scheduling the script to run daily at a specific time
schedule.every().day.at("09:48").do(generate_daily_report)
# Run the script indefinitely
while True:
schedule.run_pending()
time.sleep(1)
Comments
Post a Comment