From cf7fcc2bd3c99b5eb4bdfac2752bee2b82a593f7 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Thu, 12 Feb 2026 20:50:09 +0000
Subject: [PATCH] email everytime logic

---
 src/archrepobuild/notifications.py |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/archrepobuild/notifications.py b/src/archrepobuild/notifications.py
index 51cfd18..98663e4 100644
--- a/src/archrepobuild/notifications.py
+++ b/src/archrepobuild/notifications.py
@@ -106,7 +106,7 @@
 
     async def send(self, summary: BuildSummary, config: Config) -> bool:
         """Send email notification."""
-        if not self.config.enabled:
+        if not self.config.enabled and ((not self.config.email_everytime) and summary.failed == 0):
             return True
 
         if not self.config.to:
@@ -140,21 +140,24 @@
 
     def _send_email(self, msg: MIMEMultipart) -> None:
         """Send email synchronously (called from executor)."""
+        smtp_class = smtplib.SMTP
+        use_starttls = False
+
         if self.config.use_tls:
-            context = ssl.create_default_context()
-            with smtplib.SMTP_SSL(
-                self.config.smtp_host,
-                self.config.smtp_port,
-                context=context,
-            ) as server:
-                if self.config.username and self.config.password:
-                    server.login(self.config.username, self.config.password)
-                server.send_message(msg)
-        else:
-            with smtplib.SMTP(self.config.smtp_host, self.config.smtp_port) as server:
-                if self.config.username and self.config.password:
-                    server.login(self.config.username, self.config.password)
-                server.send_message(msg)
+            if self.config.smtp_port == 465:
+                smtp_class = smtplib.SMTP_SSL
+            else:
+                use_starttls = True
+
+        with smtp_class(self.config.smtp_host, self.config.smtp_port) as server:
+            if use_starttls:
+                context = ssl.create_default_context()
+                server.starttls(context=context)
+            
+            if self.config.username and self.config.password:
+                server.login(self.config.username, self.config.password)
+            
+            server.send_message(msg)
 
 
 class WebhookBackend(NotificationBackend):

--
Gitblit v1.10.0