mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-26 00:35:51 +03:00
[GH-ISSUE #87] Does not work with Alpine Linux's sendmail #57
Labels
No labels
awaiting feedback
bug
docker
documentation
enhancement
github_actions
invalid
pull-request
question
stale
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/mailpit#57
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sjinks on GitHub (Apr 10, 2023).
Original GitHub issue: https://github.com/axllent/mailpit/issues/87
Steps to reproduce:
mailpitcontainer:docker run -it --rm axllent/mailpitdocker execinto the container and run:Expected result: email is queued
Actual result:
In mailpit logs, I see:
RRO[2023/04/10 10:51:02] error parsing message: malformed MIME header line: To: admin@example.comMy debugging showed that
mailpitdoes not handle<CR>: the lines above with the leading'actually contain the<CR>character:is
To confirm my finding, I modified the
sendmail_pathsetting:Now it works as expected:
However, I think that
mailpitshould handle the<CR>character in the mail body (MailHog does).Unfortunately, I don't know Go good enough to submit a PR, sorry :-(
@axllent commented on GitHub (Apr 11, 2023):
Thanks for all the testing and narrowing down the issue @sjinks.
I believe the big difference here between MailHog and Mailpit is that the SMTPD server within MailHog appears to be a custom implementation which maybe isn't as RFC-compliant as it says it is (and, according to the screenshots in the PR you linked from, makes a real mess of the headers / body). Mailpit uses mhale/smtpd which complies to the RFC standards, and will reject non-compliant emails.
The RFC standards state that
CRLFis required. The issue here appears to be coming from PHP8, which, according to that bug report, now produces anCRLF(\r\n) by default (which is required by a SMTP server), rather than the formerLF(\nin < v8). It's a long thread to follow, but the PHP devs are pointing fingers to the MTA (in this case sendmail) which is making a mess of it. This would make sense if sendmail is changing all\nreturns to\r\n, which would result in\r\r\n, and which is I believe what is happening here.There are a couple of work-arounds (eg:
dos2unixas you suggested), which would remove the\rfrom the\r\nfrom PHP'smail()~ which sendmail then adds back in. Very messy, but, as you said, works....There also appears to be a new backwards-compatibility PHP INI configuration - but I couldn't get that working so that may only be PHP 8.2 (or still unreleased?), I don't know.
Either way though, I do not think the issue here is in Mailpit's SMTPD, but in the default MTA used in Alpine (which is actually busybox's sendmail implementation) - or in Alpine itself (this goes beyong my understanding unfortunately). Mailpit is simply following the RFC, and doing what it should - the email being delivered via sendmail is not compliant, so it is rejected. If I was to create a work-around within Mailpit, it would mean that Mailpit would allow non-compliant emails to be delivered, and by definition defy the point of an SMTP testing tool. I do not think that is a good solution at all.
So I'm not sure "where to" from here unfortunately, but I feel the solution lies in the sendmail version used. There are alternative sendmail implementations available in Alpine. I use msmtp in production (for Alpine docker implementations), and configure PHP to use to
mailpit sendmaildirectly in development, so I cannot say I have experience with the setup you use.@sjinks commented on GitHub (Apr 11, 2023):
Hmmm… However, it still works with Postfix:
Yes, you were right, I was able to confirm that with
and
(where
data.txtwas a email with CR LF line endings)Great, thanks! I was able to send a test email with this:
Closing then, as this is not a bug :-) Thank you!
@axllent commented on GitHub (Apr 11, 2023):
Thanks for the confirmation either way. Interesting that it works with postfix, though I suspect that is a "feature" in postfix to fix this very issue (work-around). Then again, even if postfix accepts the mail, it doesn't mean it is strictly valid, and there's no assurance other mail servers will accept it.
I'm no C expert, but I found send_r_n() which is referenced several times in sendmail.c. It sends every line with a trailing
\r\n. The lines are however split with xmalloc_fgetline() which looks to me like it splits lines with\n. This means the\ris left at the end of each line, resulting in\r\r\nbeing sent through to the SMTP server. Again, I'm no C expert, but I think the sendmail implementation in busybox is the definite cause here. I think that if you wanted a proper fix, that would be the place to start.Glad you got it working though!