-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendEmail.py
More file actions
60 lines (48 loc) · 1.66 KB
/
sendEmail.py
File metadata and controls
60 lines (48 loc) · 1.66 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
import smtplib
import os
from DatabaseFunctions import export_logs_to_text_file
from email.message import EmailMessage
def send_email(subject, body, to_email):
EMAIL_ADDRESS = "swipeinservice@gmail.com"
EMAIL_PASSWORD = "pjrm fxvr vifz ofvg"
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = EMAIL_ADDRESS
msg['To'] = to_email
msg.set_content(body)
try:
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
return "success!"
except Exception as e:
print(f"Error sending email: {e}")
return "error"
def send_logs(subject, body, to_email):
EMAIL_ADDRESS = "swipeinservice@gmail.com"
EMAIL_PASSWORD = "pjrm fxvr vifz ofvg"
# Export logs to file
log_file = 'user_logs.txt'
export_logs_to_text_file(log_file)
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = EMAIL_ADDRESS
msg['To'] = to_email
msg.set_content(body)
# Attach the log file
try:
with open(log_file, 'rb') as f:
file_data = f.read()
file_name = os.path.basename(log_file)
msg.add_attachment(file_data, maintype='text', subtype='plain', filename=file_name)
except Exception as e:
print(f"Failed to attach log file: {e}")
return
# Send the email
try:
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
print("Email with logs sent successfully!")
except Exception as e:
print(f"Error sending email: {e}")