e-mail python smtp
from email.message import EmailMessage
import smtplib
import os
import random
from dotenv import load_dotenv
from quote import quote
load_dotenv(".env")
SENDER = os.environ.get("GMAIL_USER")
PASSWORD = os.environ.get("GMAIL_PASSWORD")
def send_email(recipient, subject, body):
msg = EmailMessage()
msg.set_content(body)
msg["Subject"] = subject
msg["From"] = SENDER
msg["To"] = recipient
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.login(SENDER, PASSWORD)
server.send_message(msg)
server.quit()
quotes = quote("William Shakespeare", limit=50)
body = random.sample(quotes, k=1)[0]['quote']
send_email("[email protected]", subject="Quote of the Day", body=body)
Silly Scarab