-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemail_utils.py
More file actions
75 lines (57 loc) · 2.43 KB
/
email_utils.py
File metadata and controls
75 lines (57 loc) · 2.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
def send_ticket_email(ticket_id, data):
try:
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = os.environ.get("BREVO_API_KEY")
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(
sib_api_v3_sdk.ApiClient(configuration)
)
priority = data.get('priority')
color = {
"Urgent": "#c0392b",
"High": "#e74c3c",
"Medium": "#f39c12",
"Low": "#27ae60"
}.get(priority, "#3498db")
html_content = f"""
<html>
<body style="font-family: Arial; background:#f4f6f9; padding:20px;">
<div style="max-width:600px; margin:auto; background:white; border-radius:10px; padding:20px;">
<h2 style="background:#2c3e50; color:white; padding:10px; border-radius:5px;">
🛠 New Maintenance Ticket
</h2>
<p>A new maintenance request has been submitted.</p>
<p><b>Ticket ID:</b> #{ticket_id}</p>
<p><b>Category:</b> {data.get('category')}</p>
<p><b>Location:</b> Block {data.get('block')}, Floor {data.get('floor')}, Room {data.get('room_no')}</p>
<p><b>Priority:</b>
<span style="background:{color}; color:white; padding:5px 10px; border-radius:5px;">
{priority}
</span>
</p>
<p><b>Description:</b><br>{data.get('description')}</p>
<hr>
<p><b>Submitted By:</b><br>
{data.get('name')}<br>
{data.get('email')}<br>
{data.get('phone')}
</p>
<p style="margin-top:20px; font-size:12px; color:#777;">
Campus Maintenance Portal • Automated Notification
</p>
</div>
</body>
</html>
"""
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(
to=[{"email": "2501730151@krmu.edu.in", "name": "Maintenance Team"}],
sender={"email": "chaudharyanupam746@gmail.com", "name": "Campus Maintenance"},
subject=f"New Maintenance Ticket #{ticket_id}",
html_content=html_content
)
response = api_instance.send_transac_email(send_smtp_email)
print("✅ Email sent:", response)
except ApiException as e:
print("❌ Email failed:", e)