[GH-ISSUE #70] Autoreply error (Header values can't contain newline) #38

Closed
opened 2026-02-27 10:25:28 +03:00 by kerem · 4 comments
Owner

Originally created by @whiteSpaceX on GitHub (Aug 5, 2020).
Original GitHub issue: https://github.com/modoboa/modoboa-postfix-autoreply/issues/70

Morning, since I updated to Modoboa 1.15 with Django 3.6 and Postfix-autoreply 1.6.0. I am getting this error sending emails to an account with autoreply on:

Remote Server returned 'XXX X.X.X < #5.3.0 x-unix; Traceback (most recent call last): File "/srv/modoboa/instance/manage.py", line 22, in execute_from_command_line(sys.argv) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/init.py", line 381, in execute_from_command_line utility.execute() File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/init.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/srv/modoboa/env/lib/python3.7/site-packages/modoboa_postfix_autoreply/management/commands/autoreply.py", line 214, in handle send_autoreply(sender, mbox, armessage, original_msg) File "/srv/modoboa/env/lib/python3.7/site-packages/modoboa_postfix_autoreply/management/commands/autoreply.py", line 107, in send_autoreply msg.send() File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 291, in send return self.get_connection(fail_silently).send_messages([self]) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 110, in send_messages sent = self._send(message) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 124, in _send message = email_message.message() File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 275, in message msg[name] = value File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 169, in setitem name, val = forbid_multi_line_headers(name, val, self.encoding) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 60, in forbid_multi_line_headers raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) django.core.mail.message.BadHeaderError: Header values can't contain newlines (got '\n AM0PR03MB553776DDF4AEA9363446D10FB94B0@AM0PR03MB5537.eurprd03.prod.outlook.com' for header 'In-Reply-To')>'

Originally created by @whiteSpaceX on GitHub (Aug 5, 2020). Original GitHub issue: https://github.com/modoboa/modoboa-postfix-autoreply/issues/70 Morning, since I updated to Modoboa 1.15 with Django 3.6 and Postfix-autoreply 1.6.0. I am getting this error sending emails to an account with autoreply on: Remote Server returned 'XXX X.X.X < #5.3.0 x-unix; Traceback (most recent call last): File "/srv/modoboa/instance/manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/srv/modoboa/env/lib/python3.7/site-packages/modoboa_postfix_autoreply/management/commands/autoreply.py", line 214, in handle send_autoreply(sender, mbox, armessage, original_msg) File "/srv/modoboa/env/lib/python3.7/site-packages/modoboa_postfix_autoreply/management/commands/autoreply.py", line 107, in send_autoreply msg.send() File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 291, in send return self.get_connection(fail_silently).send_messages([self]) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 110, in send_messages sent = self._send(message) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 124, in _send message = email_message.message() File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 275, in message msg[name] = value File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 169, in __setitem__ name, val = forbid_multi_line_headers(name, val, self.encoding) File "/srv/modoboa/env/lib/python3.7/site-packages/django/core/mail/message.py", line 60, in forbid_multi_line_headers raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) django.core.mail.message.BadHeaderError: Header values can't contain newlines (got '\n <AM0PR03MB553776DDF4AEA9363446D10FB94B0@AM0PR03MB5537.eurprd03.prod.outlook.com>' for header 'In-Reply-To')>'
kerem 2026-02-27 10:25:28 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@lmfrazao commented on GitHub (Nov 19, 2020):

Hello, using modoboa 1.17 and python 3.6

still have this problem.

is there any way to fix this ?

update python to 3.7 or 3.8 can fix this ?

thank you.

<!-- gh-comment-id:730378031 --> @lmfrazao commented on GitHub (Nov 19, 2020): Hello, using modoboa 1.17 and python 3.6 still have this problem. is there any way to fix this ? update python to 3.7 or 3.8 can fix this ? thank you.
Author
Owner

@harryfoster commented on GitHub (Jul 16, 2021):

Exact same thing for myself. I think it's only particular clients (Outlook?) and when replying to an email:

    "/srv/modoboa/env/lib64/python3.6/site-packages/django/core/mail/message.py",
    line 62, in forbid_multi_line_headers     raise BadHeaderError("Header
    values can't contain newlines (got %r for header %r)" % (val, name))
    django.core.mail.message.BadHeaderError: Header values can't contain
    newlines (got '\n
    <XXXYYYZZZ@XXXYYYZZZ.GBR1234.PROD.OUTLOOK.COM>'
    for header 'In-Reply-To')

Modoboa | 1.17.0
Postfix autoreply | 1.6.0

I think it gets incorporated at this location in /modoboa_postfix_autoreply/management/commands/autoreply.py:

message_id = original_msg.get("Message-ID")
if message_id:
    headers.update({"In-Reply-To": message_id, "References": message_id})

Outlook for some reason puts the Message_ID on new line, where as most other MTAs don't. We end up then carrying that /n over to the In-Reply-To header which Django doesn't like due to forbid_multi_line_headers. Maybe a quick newline strip() will sort this? This is just a quick glance, I haven't sat down with a debugger.

I'm going to experiment on my dev box.

<!-- gh-comment-id:881312295 --> @harryfoster commented on GitHub (Jul 16, 2021): Exact same thing for myself. I think it's only particular clients (Outlook?) and when replying to an email: ``` "/srv/modoboa/env/lib64/python3.6/site-packages/django/core/mail/message.py", line 62, in forbid_multi_line_headers raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) django.core.mail.message.BadHeaderError: Header values can't contain newlines (got '\n <XXXYYYZZZ@XXXYYYZZZ.GBR1234.PROD.OUTLOOK.COM>' for header 'In-Reply-To') ``` Modoboa | 1.17.0 Postfix autoreply | 1.6.0 I think it gets incorporated at this location in /modoboa_postfix_autoreply/management/commands/autoreply.py: message_id = original_msg.get("Message-ID") if message_id: headers.update({"In-Reply-To": message_id, "References": message_id}) Outlook for some reason puts the Message_ID on new line, where as most other MTAs don't. We end up then carrying that /n over to the In-Reply-To header which Django doesn't like due to forbid_multi_line_headers. Maybe a quick newline strip() will sort this? This is just a quick glance, I haven't sat down with a debugger. I'm going to experiment on my dev box.
Author
Owner

@lmfrazao commented on GitHub (Jul 19, 2021):

Still have that problem, only tested on outlook.

Luís Frazão | Bild Corp
+351 914120170
www.bild.pt


From: Harry Foster @.>
Sent: Friday, July 16, 2021 10:33:09 AM
To: modoboa/modoboa-postfix-autoreply @.
>
Cc: lmfrazao @.>; Comment @.>
Subject: Re: [modoboa/modoboa-postfix-autoreply] Autoreply error (Header values can't contain newline) (#70)

Exact same thing for myself. I think it's only particular clients (Outlook?) and when replying to an email:

"/srv/modoboa/env/lib64/python3.6/site-packages/django/core/mail/message.py",
line 62, in forbid_multi_line_headers     raise BadHeaderError("Header
values can't contain newlines (got %r for header %r)" % (val, name))
django.core.mail.message.BadHeaderError: Header values can't contain
newlines (got '\n
<XXXYYYZZZ@XXXYYYZZZ.GBR1234.PROD.OUTLOOK.COM>'
for header 'In-Reply-To')

Modoboa | 1.17.0
Postfix autoreply | 1.6.0

I think it gets incorporated at this location:

message_id = original_msg.get("Message-ID")
if message_id:
headers.update({"In-Reply-To": message_id, "References": message_id})

Outlook for some reason puts the Message_ID on new line, where as most other MTAs don't. We end up then carrying that /n over to the In-Reply-To header which Django doesn't like due to forbid_multi_line_headers. Maybe a quick newline strip() will sort this? This is just a quick glance, I haven't sat down with a debugger.

I'm going to experiment on my dev box.


You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/modoboa/modoboa-postfix-autoreply/issues/70#issuecomment-881312295, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AICKR6UIXL4NZ2INWAFCLOLTX74FLANCNFSM4PVDTVGA.

<!-- gh-comment-id:882875462 --> @lmfrazao commented on GitHub (Jul 19, 2021): Still have that problem, only tested on outlook. Luís Frazão | Bild Corp +351 914120170 www.bild.pt ________________________________ From: Harry Foster ***@***.***> Sent: Friday, July 16, 2021 10:33:09 AM To: modoboa/modoboa-postfix-autoreply ***@***.***> Cc: lmfrazao ***@***.***>; Comment ***@***.***> Subject: Re: [modoboa/modoboa-postfix-autoreply] Autoreply error (Header values can't contain newline) (#70) Exact same thing for myself. I think it's only particular clients (Outlook?) and when replying to an email: "/srv/modoboa/env/lib64/python3.6/site-packages/django/core/mail/message.py", line 62, in forbid_multi_line_headers raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) django.core.mail.message.BadHeaderError: Header values can't contain newlines (got '\n <XXXYYYZZZ@XXXYYYZZZ.GBR1234.PROD.OUTLOOK.COM>' for header 'In-Reply-To') Modoboa | 1.17.0 Postfix autoreply | 1.6.0 I think it gets incorporated at this location: message_id = original_msg.get("Message-ID") if message_id: headers.update({"In-Reply-To": message_id, "References": message_id}) Outlook for some reason puts the Message_ID on new line, where as most other MTAs don't. We end up then carrying that /n over to the In-Reply-To header which Django doesn't like due to forbid_multi_line_headers. Maybe a quick newline strip() will sort this? This is just a quick glance, I haven't sat down with a debugger. I'm going to experiment on my dev box. — You are receiving this because you commented. Reply to this email directly, view it on GitHub<https://github.com/modoboa/modoboa-postfix-autoreply/issues/70#issuecomment-881312295>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AICKR6UIXL4NZ2INWAFCLOLTX74FLANCNFSM4PVDTVGA>.
Author
Owner

@call2pedro commented on GitHub (Oct 19, 2021):

I have same issue here at my box. Many times for Office 365 autoreply do not work as should and generates error as you mentioned.

<!-- gh-comment-id:946588952 --> @call2pedro commented on GitHub (Oct 19, 2021): I have same issue here at my box. Many times for Office 365 autoreply do not work as should and generates error as you mentioned.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-postfix-autoreply-modoboa#38
No description provided.