From a5d7127109bf17202fcf657b4b251ebd8e23358a Mon Sep 17 00:00:00 2001 From: pzl Date: Tue, 20 May 2025 14:55:03 -0400 Subject: [PATCH] construct smtp.py email wrap long lines RFC 5322 2.1.1 requires <=998 chars per line. If matches are included, and are very long lines, the email will be rejected. Constructing the mail as a message instead of a subpart (mimetext) fixes this --- config/action.d/smtp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/action.d/smtp.py b/config/action.d/smtp.py index 40eda1b5..69e337b6 100644 --- a/config/action.d/smtp.py +++ b/config/action.d/smtp.py @@ -19,7 +19,8 @@ import socket import smtplib -from email.mime.text import MIMEText +import email.policy +from email.message import EmailMessage from email.utils import formatdate, formataddr from fail2ban.server.actions import ActionBase, CallingMap @@ -151,7 +152,8 @@ class SMTPAction(ActionBase): See Python `smtplib` for full list of other possible exceptions. """ - msg = MIMEText(text) + msg = EmailMessage(policy=email.policy.SMTP) + msg.set_content(text) msg['Subject'] = subject msg['From'] = formataddr((self.fromname, self.fromaddr)) msg['To'] = self.toaddr