File size: 3,062 Bytes
2f3c093
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

class AlertsNotifications:
    def __init__(self, smtp_server, smtp_port, smtp_user, smtp_password):
        self.smtp_server = smtp_server
        self.smtp_port = smtp_port
        self.smtp_user = smtp_user
        self.smtp_password = smtp_password

    def send_email(self, recipient, subject, body):
        msg = MIMEMultipart()
        msg['From'] = self.smtp_user
        msg['To'] = recipient
        msg['Subject'] = subject

        msg.attach(MIMEText(body, 'plain'))

        try:
            with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
                server.starttls()
                server.login(self.smtp_user, self.smtp_password)
                server.sendmail(self.smtp_user, recipient, msg.as_string())
                print(f"Email sent to {recipient}")
        except Exception as e:
            print(f"Failed to send email: {e}")

    def send_alert(self, alert_type, alert_details):
        subject = f"Alert: {alert_type}"
        body = f"Details: {alert_details}"
        self.send_email("admin@example.com", subject, body)

    def notify_device_connection(self, device_id):
        subject = "Device Connected"
        body = f"Device {device_id} has been connected."
        self.send_email("admin@example.com", subject, body)

    def notify_device_disconnection(self, device_id):
        subject = "Device Disconnected"
        body = f"Device {device_id} has been disconnected."
        self.send_email("admin@example.com", subject, body)

    def integrate_with_new_components(self, new_component_data):
        subject = "New Component Integration"
        body = f"New component data: {new_component_data}"
        self.send_email("admin@example.com", subject, body)

    def ensure_compatibility(self, existing_data, new_component_data):
        subject = "Compatibility Check"
        body = f"Existing data: {existing_data}\nNew component data: {new_component_data}"
        self.send_email("admin@example.com", subject, body)

    def integrate_with_main_gui(self, main_gui):
        self.main_gui = main_gui

    def update_send_alert(self, alert_type, alert_details):
        subject = f"Alert: {alert_type}"
        body = f"Details: {alert_details}"
        self.send_email("admin@example.com", subject, body)
        self.main_gui.update_alerts(alert_type, alert_details)

    def update_send_email(self, recipient, subject, body):
        self.send_email(recipient, subject, body)
        self.main_gui.update_emails(recipient, subject, body)

    def send_alert_for_module(self, module_name, alert_details):
        subject = f"Alert: {module_name}"
        body = f"Details: {alert_details}"
        self.send_email("admin@example.com", subject, body)

    def send_notification_for_module(self, module_name, notification_details):
        subject = f"Notification: {module_name}"
        body = f"Details: {notification_details}"
        self.send_email("admin@example.com", subject, body)