1 (edited by marius.timukas 2020-11-05 05:51:27)

Topic: quarantined Emails - notification

- iRedMail version (check /etc/iredmail-release): 1.3.2
- Deployed with iRedMail Easy or the downloadable installer? Downloadable
- Linux/BSD distribution name and version: CentOS 7.8
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Yes, 4.6
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.


After upgrade to iRedAdmin-Pro 4.6, I found a problem with notification about quarantined email.

[root@mail ~]# /usr/bin/python3 /var/www/iredadmin/tools/notify_quarantined_recipients.py --force-all
* + << ERROR >> Error while sending notification email to username@domain.ltd: TypeError("a bytes-like object is required, not 'str'",)

After each run of the script, a new message appears in quarantine list. The notification message is stopped with the SPAM flag.

X-Amavis-Alert:     BAD HEADER SECTION, MIME error: error: unexpected end of header
X-Spam-Status:      Yes, score=5.138 tag=-100 tag2=5 kill=5 tests=[BAYES_20=-0.001, EMPTY_MESSAGE=2.32, MISSING_HEADERS=1.021, MISSING_SUBJECT=1.799, NO_RELAYS=-0.001] autolearn=no autolearn_force=no



Re: quarantined Emails - notification

Confirmed it's a bug of iRedAdmin-Pro and fixed moment ago. Here's patch for iRedAdmin-Pro-SQL-4.6 and iRedAdmin-Pro-LDAP-4.7. If you're not familiar with patch, contact us to get a patched version.

diff --git a/libs/iredutils.py b/libs/iredutils.py
index 18f3962e..c1bc3cc4 100644
--- a/libs/iredutils.py
+++ b/libs/iredutils.py
@@ -836,9 +836,10 @@ def sendmail_with_cmd(from_address, recipients, message_text):
     cmd = [settings.CMD_SENDMAIL, "-f", from_address, recipients]
+    msg = str2bytes(message_text)
         p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
-        p.stdin.write(message_text)
+        p.stdin.write(msg)


Buy me a cup of coffee ($5) to support iRedMail:

buy me a cup of coffee


Re: quarantined Emails - notification

marius.timukas wrote:

TypeError("a bytes-like object is required, not 'str'",)

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes instead. We can convert bytes to string using bytes class decode() instance method, So you need to decode the bytes object to produce a string. In Python 3 , the default encoding is "utf-8" , so you can use directly:

b"python byte to string".decode("utf-8")

Python makes a clear distinction between bytes and strings . Bytes objects contain raw data — a sequence of octets — whereas strings are Unicode sequences . Conversion between these two types is explicit: you encode a string to get bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes to get a string. Clients of these functions should be aware that such conversions may fail, and should consider how failures are handled.