-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathX_Email_Multi.py
176 lines (159 loc) · 8.33 KB
/
X_Email_Multi.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- encoding: utf-8 -*-
# Copyright SafeX (https://github.com/kyoo-147/SafeX) 2024. All Rights Reserved.
# MIT License (https://opensource.org/licenses/MIT)
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import os
from datetime import datetime
def get_receiver_emails(file_path):
with open(file_path, 'r') as file:
emails = [line.strip() for line in file if line.strip()]
return emails
def unknown_send_email(name, image_path):
# Admin Email
sender = "[email protected]"
receivers = get_receiver_emails("X_Utils/Receivers_User.txt")
location = "Lot E2, Yen Hoa New Urban Area - Cau Giay - Hanoi"
# Get security password from Enviroment Ubuntu
password = os.getenv("EMAIL_PASSWORD_SENT")
subject = "[NaVin Warning]: Unidentified object detection warning"
body = f"""
<html>
<body >
<table style="background-color: #78BA01; color: #000000; width: 100%;">
<tr>
<td style="padding: 10px; "><img src="cid:company_logo" alt="Company Logo" style="width:100px;height:100px;"></td>
<td style="padding: 10px;">
<h1 style="margin: 0; font-size: 24px;">NaVin AIF Technology Company Cloud Data Center</h1>
<h2 style="margin: 0; font-size: 15px;">Our Body Of Work</h2>
</td>
</tr>
</table>
<h3>Notification: Warning detects objects not in the system with suspicious activity</h3>
<p>Potentially compromised credentials for the SafeX Model X system (Note: Need to double check unknown object information)</p>
<p>Hello, User</p>
<p>The SafeX system has detected an unknown object: {name}.</p>
<p>Here are the details:</p>
<ul>
<li>Date and Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</li>
<li>Location: {location}</li>
</ul>
<p>Please see attached detailed facial images to make the quickest decisions. If the detection time is too long, the system will activate the dangerous alarm mode.</p>
<br>
<p>Best regards,<br>Security Team Trust & Safety</p>
<hr>
<p><b>NaVin AIF Technology Company</b></p>
<p>Let us help protect your safety! See detailed information about the demo at <a href="https://www.youtube.com/@NaVin_AIF_Tech/featured">NaVin AIF</a>, Trust, and Safety.</p>
<p>Subscribe and view previous issues <a href="mailto:[email protected]">here</a>.</p>
<p>Thoughts, upgrades, maintenance, feedback? Please send it <a href="mailto:[email protected]">NaVin AIF</a>. To avoid our newsletter falling into the spam folder causing security disruption, by adding our email address to your contact list.</p>
<p>NaVin AIF Technology Company, Ho Chi Minh City, VietNam</p>
<p><a href="https://www.youtube.com/@NaVin_AIF_Tech/featured">Youtube</a> | <a href="https://github.com/kyoo-147">Github</a></p>
</body>
</html>
"""
message = MIMEMultipart()
message["From"] = sender
message["To"] = ", ".join(receivers) # Gộp danh sách địa chỉ email thành một chuỗi ngăn cách bởi dấu phẩy
message["Subject"] = subject
# Attach HTML body
message.attach(MIMEText(body, "html"))
# Attach company logo
try:
with open("X_Test/Image/X_Logo.png", 'rb') as logo_file:
logo = MIMEImage(logo_file.read())
logo.add_header('Content-ID', '<company_logo>')
message.attach(logo)
except FileNotFoundError:
print("Failed to attach logo. File not found.")
return
# Attach image of detected face
try:
with open(image_path, 'rb') as img_file:
img = MIMEImage(img_file.read())
img.add_header('Content-Disposition', 'attachment', filename=image_path)
message.attach(img)
except FileNotFoundError:
print(f"Failed to attach image. File {image_path} not found.")
return
try:
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(sender, password)
server.sendmail(sender, receivers, message.as_string()) # Sử dụng danh sách receivers
print("[NaVin Notifications]: Email sent successfully.")
except Exception as e:
print(f"[NaVin Warning]: Failed to send email. Error: {e}")
def known_send_email(name, image_path):
# Admin Email
sender = "[email protected]"
receivers = get_receiver_emails("X_Utils/Receivers_User.txt")
location = "Lot E2, Yen Hoa New Urban Area - Cau Giay - Hanoi"
# Get security password from Enviroment Ubuntu
password = os.getenv("EMAIL_PASSWORD_SENT")
subject = "[NaVin Notification]: Notice of object detection in system data"
body = f"""
<html>
<body >
<table style="background-color: #78BA01; color: #000000; width: 100%;">
<tr>
<td style="padding: 10px; "><img src="cid:company_logo" alt="Company Logo" style="width:100px;height:100px;"></td>
<td style="padding: 10px;">
<h1 style="margin: 0; font-size: 24px;">NaVin AIF Technology Company Cloud Data Center</h1>
<h2 style="margin: 0; font-size: 15px;">Our Body Of Work</h2>
</td>
</tr>
</table>
<h3>Notification: Notification that an object has been detected in the system within the range that can be received</h3>
<p>Authentication information will be stored and behavior monitored (Note: Need to carefully check subject information to confirm behavior)</p>
<p>Hello, User</p>
<p>The SafeX system has detected the specified object: {name}.</p>
<p>Here are the details:</p>
<ul>
<li>Date and Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</li>
<li>Location: {location}</li>
</ul>
<p>Please see attached detailed facial image to confirm. If the detection time is too long, the system will notify you about the confirmation status.</p>
<br>
<p>Best regards,<br>Security Team Trust & Safety</p>
<hr>
<p><b>NaVin AIF Technology Company</b></p>
<p>Let us help protect your safety! See detailed information about the demo at <a href="https://www.youtube.com/@NaVin_AIF_Tech/featured">NaVin AIF</a>, Trust, and Safety.</p>
<p>Subscribe and view previous issues <a href="mailto:[email protected]">here</a>.</p>
<p>Thoughts, upgrades, maintenance, feedback? Please send it <a href="mailto:[email protected]">NaVin AIF</a>. To avoid our newsletter falling into the spam folder causing security disruption, by adding our email address to your contact list.</p>
<p>NaVin AIF Technology Company, Ho Chi Minh City, VietNam</p>
<p><a href="https://www.youtube.com/@NaVin_AIF_Tech/featured">Youtube</a> | <a href="https://github.com/kyoo-147">Github</a></p>
</body>
</html>
"""
message = MIMEMultipart()
message["From"] = sender
message["To"] = ", ".join(receivers) # Gộp danh sách địa chỉ email thành một chuỗi ngăn cách bởi dấu phẩy
message["Subject"] = subject
# Attach HTML body
message.attach(MIMEText(body, "html"))
# Attach company logo
try:
with open("X_Test/Image/X_Logo.png", 'rb') as logo_file:
logo = MIMEImage(logo_file.read())
logo.add_header('Content-ID', '<company_logo>')
message.attach(logo)
except FileNotFoundError:
print("Failed to attach logo. File not found.")
return
# Attach image of detected face
try:
with open(image_path, 'rb') as img_file:
img = MIMEImage(img_file.read())
img.add_header('Content-Disposition', 'attachment', filename=image_path)
message.attach(img)
except FileNotFoundError:
print(f"Failed to attach image. File {image_path} not found.")
return
try:
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(sender, password)
server.sendmail(sender, receivers, message.as_string()) # Sử dụng danh sách receivers
print("[NaVin Notifications]: Email sent successfully.")
except Exception as e:
print(f"[NaVin Warning]: Failed to send email. Error: {e}")