-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail_fun.py
39 lines (31 loc) · 1.15 KB
/
email_fun.py
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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(customer_name, customer_email, order_id, order_total, delivery_time):
"""Send purchase confirmation email"""
smtp_server = "smtp.gmail.com"
smtp_port = 587
smtp_username = "[email protected]"
smtp_password = "taer umkt psfw mpgu"
msg = MIMEMultipart()
msg["From"] = smtp_username
msg["To"] = customer_email
msg["Subject"] = "Purchase Confirmation"
body = f"""Dear {customer_name},
Thank you for your purchase. Your order (ID: {order_id}) of ₹{order_total:.2f} has been confirmed.
Expected delivery time: {delivery_time}
Sincerely,
Your Name
"""
msg.attach(MIMEText(body, "plain"))
try:
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login(smtp_username, smtp_password)
server.sendmail(smtp_username, customer_email, msg.as_string())
server.quit()
print(
f"Purchase confirmation email sent to {customer_email} for order {order_id}."
)
except Exception as e:
print(f"Error sending email: {e}")