Skip to content

Commit ea90fa7

Browse files
authored
Add demo email sending script
1 parent 49560ad commit ea90fa7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/emailservice/send_demo.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import sys
3+
import smtplib
4+
from mail_helpers import build_order_confirmation_email
5+
6+
def main(argv=None):
7+
argv = argv or sys.argv[1:]
8+
if len(argv) < 3:
9+
print("Usage: python -m emailservice.send_demo <name> <email> <order_id>")
10+
sys.exit(2)
11+
12+
name, email, order_id = argv[0], argv[1], argv[2]
13+
body = f"Hello {name},\n\nThis is a demo confirmation for order #{order_id}.\n- Hipster Shop\n"
14+
15+
msg = build_order_confirmation_email(name, email, order_id, body)
16+
17+
host = os.getenv("SMTP_HOST", "localhost")
18+
port = int(os.getenv("SMTP_PORT", "1025"))
19+
20+
with smtplib.SMTP(host, port) as s:
21+
s.send_message(msg)
22+
23+
print(f"Sent demo confirmation for order #{order_id} to {email}")
24+
25+
if __name__ == "__main__":
26+
main()

0 commit comments

Comments
 (0)