88from src .config import app
99from src .models import SmptEamilPasswordConfig , DashboardSettings
1010
11- def send_email (receiver_email , subject , body , attachment_path = None , is_html = False ):
11+ system_name = os .uname ().sysname
12+
13+ def send_email (receiver_email , subject , body , attachment_path = None , is_html = False , bypass_alerts = False ):
1214
1315 if isinstance (receiver_email , str ):
1416 receiver_email = [receiver_email ] # Convert single address to list
1517
1618 with app .app_context ():
17- dashboard_settings = DashboardSettings .query .first ()
18- if dashboard_settings :
19- enable_alerts = dashboard_settings .enable_alerts
20- if not enable_alerts :
21- print ("Email alerts are disabled. Please enable them in the settings." )
22- flash ("Email alerts are disabled. Please enable them in the settings." , "danger" )
23- return redirect (url_for ('general_settings' ))
24-
19+ if not bypass_alerts :
20+ dashboard_settings = DashboardSettings .query .first ()
21+ if dashboard_settings :
22+ enable_alerts = dashboard_settings .enable_alerts
23+ if not enable_alerts :
24+ print ("Email alerts are disabled. Please enable them in the settings." )
25+ flash ("Email alerts are disabled. Please enable them in the settings." , "danger" )
26+ return redirect (url_for ('general_settings' ))
27+
2528 email_password = SmptEamilPasswordConfig .query .first ()
2629 if not email_password :
2730 print ("SMTP email credentials not found. Please set EMAIL_ADDRESS and EMAIL_PASSWORD environment variables." )
@@ -35,11 +38,12 @@ def send_email(receiver_email, subject, body, attachment_path=None, is_html=Fals
3538
3639 for email in receiver_email :
3740 try :
41+ server_name = os .uname ().nodename
3842 # Create a multipart message
3943 msg = MIMEMultipart ()
4044 msg ['From' ] = EMAIL_ADDRESS
4145 msg ['To' ] = email
42- msg ['Subject' ] = "SystemGuard Alert: " + subject
46+ msg ['Subject' ] = "SystemGuard Alert from " + system_name + " (" + server_name + "): " + subject
4347 # Append message to the body
4448 append_message = "This is an automated email from the SystemGuard application. Please do not reply to this email."
4549
0 commit comments