-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailer.py
More file actions
25 lines (21 loc) · 896 Bytes
/
emailer.py
File metadata and controls
25 lines (21 loc) · 896 Bytes
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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(to_email, subject, content):
from_email = "Your-Email" #Replace Your ID
app_password = "Your-Password" # 🔐 Replace with env variable in production
message = MIMEMultipart("alternative")
message['From'] = from_email
message['To'] = to_email
message['Subject'] = subject
# Add both plain and HTML parts
message.attach(MIMEText(content, 'plain'))
message.attach(MIMEText(f"<html><body><p>{content}</p></body></html>", 'html'))
try:
with smtplib.SMTP('smtp.gmail.com', 587) as server:
server.starttls()
server.login(from_email, app_password)
server.send_message(message)
print("📧 Email sent successfully!")
except Exception as e:
print(f"❌ Failed to send email: {e}")