-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathX_Email_Sing.py
233 lines (195 loc) · 9.36 KB
/
X_Email_Sing.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -*- encoding: utf-8 -*-
# Copyright SafeX (https://github.com/kyoo-147/SafeX) 2024. All Rights Reserved.
# MIT License (https://opensource.org/licenses/MIT)
# Lưu ý về bảo mật: Lưu mật khẩu trong mã nguồn là không an toàn và có thể dẫn đến rủi ro bảo mật. Hãy cân nhắc các biện pháp thay thế như: Sử dụng biến môi trường để lưu mật khẩu và truy xuất trong mã. Sử dụng file cấu hình được mã hóa và giải mã mật khẩu khi chạy mã.
# import smtplib
# from email.mime.text import MIMEText
# def send_email(name):
# sender = "[email protected]"
# receiver = "[email protected]"
# password = "otmn dyaw kimc inxc"
# message = MIMEText(f"A face was recognized: {name}")
# message["Subject"] = "[NaVin Warning]:Face Recognition Alert"
# message["From"] = sender
# message["To"] = receiver
# with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
# server.login(sender, password)
# server.sendmail(sender, receiver, message.as_string())
# print("Email sent successfully.")
# name = 'Uknown'
# send_email(name)
# import smtplib
# from email.mime.text import MIMEText
# from email.mime.multipart import MIMEMultipart
# from email.mime.image import MIMEImage
# import os
# def send_email(name, image_path):
# sender = "[email protected]"
# receiver = "[email protected]"
# # password = "otmn dyaw kimc inxc" # Thay thế bằng mật khẩu ứng dụng của bạn
# # Security with password enviroment, you can set in your enviroment
# password = os.getenv("EMAIL_PASSWORD_SENT")
# subject = "[NaVin Warning]: Unidentified object detection warning"
# body = f"A face was recognized: {name}"
# message = MIMEMultipart()
# message["From"] = sender
# message["To"] = receiver
# message["Subject"] = subject
# message.attach(MIMEText(body, "plain"))
# # Attach image
# 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, receiver, message.as_string())
# print("Email sent successfully.")
# except Exception as e:
# print(f"Failed to send email. Error: {e}")
# name = 'Unknown'
# image_path = 'X_Image_Tracking/unknown/user_face_unkonwm_20240606_162553_835_6.jpg' # Thay bằng đường dẫn tới hình ảnh của bạn
# send_email(name, image_path)
# 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 send_email(name, image_path):
# sender = "[email protected]"
# receiver = "[email protected]"
# password = "otmn dyaw kimc inxc" # Thay thế bằng mật khẩu ứng dụng của bạn
# subject = "[NaVin Warning]: Face Recognition Alert"
# body = f"""
# <html>
# <body>
# <p>Hello,</p>
# <p>A face was recognized: {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: Main Entrance</li>
# </ul>
# <p>Please find the attached image for your reference.</p>
# <br>
# <p>Best regards,<br>
# Security Team</p>
# <hr>
# <p><b>Work With Andrew Ng</b></p>
# <p>Join the teams that are bringing AI to the world! Check out job openings at <a href="https://www.deeplearning.ai">DeepLearning.AI</a>, AI Fund, and Landing AI.</p>
# <p>Subscribe and view previous issues <a href="https://www.deeplearning.ai/thebatch">here</a>.</p>
# <p>Thoughts, suggestions, feedback? Please send to <a href="mailto:[email protected]">[email protected]</a>. Avoid our newsletter ending up in your spam folder by adding our email address to your contacts list.</p>
# <p>DeepLearning.AI, 195 Page Mill Road, Suite 115, Palo Alto, CA 94306, United States</p>
# <p><a href="https://www.deeplearning.ai/unsubscribe">Unsubscribe</a> | <a href="https://www.deeplearning.ai/manage-preferences">Manage preferences</a></p>
# </body>
# </html>
# """
# message = MIMEMultipart()
# message["From"] = sender
# message["To"] = receiver
# message["Subject"] = subject
# message.attach(MIMEText(body, "html"))
# # Attach image
# 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, receiver, message.as_string())
# print("Email sent successfully.")
# except Exception as e:
# print(f"Failed to send email. Error: {e}")
# name = 'Unknown'
# image_path = 'X_Image_Tracking/unknown/user_face_unkonwm_20240606_162550_831_6.jpg' # Thay bằng đường dẫn tới hình ảnh của bạn
# send_email(name, image_path)
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 send_email(name, image_path):
sender = "[email protected]"
receiver = "[email protected]"
password = os.getenv("EMAIL_PASSWORD_SENT") # Lấy mật khẩu từ biến môi trường
subject = "[NaVin Warning]: Face Recognition Alert"
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;">NaVin AIF Technology Company Cloud Data Center</h1>
<h2 style="margin: 0;">Our Body Of Work</h2>
</td>
</tr>
</table>
<h3>Notification: Suspicious Activity Alert</h3>
<p>Potentially compromised credentials for Google Cloud Platform/API project safex-003</p>
<p>Hello,</p>
<p>A face was recognized: {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: Main Entrance</li>
</ul>
<p>Please find the attached image for your reference.</p>
<br>
<p>Best regards,<br>Security Team Trust & Safety</p>
<hr>
<p><b>Work With Andrew Ng</b></p>
<p>Join the teams that are bringing AI to the world! Check out job openings at <a href="https://www.deeplearning.ai">DeepLearning.AI</a>, AI Fund, and Landing AI.</p>
<p>Subscribe and view previous issues <a href="https://www.deeplearning.ai/thebatch">here</a>.</p>
<p>Thoughts, suggestions, feedback? Please send to <a href="mailto:[email protected]">[email protected]</a>. Avoid our newsletter ending up in your spam folder by adding our email address to your contacts list.</p>
<p>DeepLearning.AI, 195 Page Mill Road, Suite 115, Palo Alto, CA 94306, United States</p>
<p><a href="https://www.deeplearning.ai/unsubscribe">Unsubscribe</a> | <a href="https://www.deeplearning.ai/manage-preferences">Manage preferences</a></p>
</body>
</html>
"""
message = MIMEMultipart()
message["From"] = sender
message["To"] = receiver
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, receiver, message.as_string())
print("Email sent successfully.")
except Exception as e:
print(f"Failed to send email. Error: {e}")
name = 'Unknown'
image_path = 'X_Image_Tracking/unknown/user_face_unkonwm_20240606_162550_830_6.jpg' # Thay bằng đường dẫn tới hình ảnh của bạn
send_email(name, image_path)