-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.py
More file actions
47 lines (39 loc) · 1.26 KB
/
send.py
File metadata and controls
47 lines (39 loc) · 1.26 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
"""
Example: sending the built email via SMTP.
Uses Python's built-in smtplib and email modules.
Configure SMTP settings below.
For ESP-specific sending, consider:
- SendGrid: pip install sendgrid
- Amazon SES: pip install boto3
- Postmark: pip install postmarker
- Mailgun: pip install requests (use REST API)
"""
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
with open("dist/welcome-merged.html") as f:
html = f.read()
with open("dist/welcome.txt") as f:
text = f.read()
# Configure your SMTP server
SMTP_HOST = "smtp.example.com"
SMTP_PORT = 587
SMTP_USER = "your-username"
SMTP_PASS = "your-password"
FROM_ADDR = "noreply@example.com"
TO_ADDR = "alice@example.com"
msg = MIMEMultipart("alternative")
msg["Subject"] = "Welcome!"
msg["From"] = FROM_ADDR
msg["To"] = TO_ADDR
msg.attach(MIMEText(text, "plain"))
msg.attach(MIMEText(html, "html"))
# Uncomment to send:
# with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as server:
# server.starttls()
# server.login(SMTP_USER, SMTP_PASS)
# server.sendmail(FROM_ADDR, TO_ADDR, msg.as_string())
# print("sent")
print("SMTP config not set — edit send.py with your credentials.")
print(f"HTML length: {len(html)} bytes")
print(f"Text length: {len(text)} bytes")