mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-26 00:35:51 +03:00
[GH-ISSUE #153] Sending emails from PHP container to Mailpit running in another container does nothing #103
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#103
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 @back-2-95 on GitHub (Aug 14, 2023).
Original GitHub issue: https://github.com/axllent/mailpit/issues/153
We are replacing MailHog with Mailpit in our tool Stohenge: https://github.com/druidfi/stonehenge/pull/76
We have a problem getting email sent from PHP containers to host's port 1025. Noteworthy is that sending emails with curl from those same containers work just fine which I guess at least verifies that Mailpit is running just fine. When sending email through PHP (sendmail), we get no errors to logs or on terminal.
This is current setup & situation from the PR above ^^:
Mailpit is attached to
localhost:1025from a Docker container and is running with following flags:Contents of
email.txt:Works
Sending email from host (macOS) with Curl:
Sending email from another container with Curl:
Not working:
Sendmail configured for PHP as inside another container:
Sending email from another container with PHP
mail()function:@axllent commented on GitHub (Aug 14, 2023):
Considering you're running Mailpit in verbose mode, what output are you getting from the Mailpit container when you try connect/send from the PHP container?
I think it's one of a few things:
Firstly, is there are particular reason you're including
--smtp-auth-accept-anyor even--smtp-auth-allow-insecure? Please try with justmailpit --verbose --smtp=0.0.0.0:1025as I'm pretty sure you're not proving any login details from sendmail, so adding--smtp-auth-accept-anymeans Mailpit tells the SMTP client it requires authentication ~ even if it accepts anything (curl just ignores this).Secondly, what
sendmailis your PHP container using? If it's the busybox implementation including in Alpine Linux, please note that it is extremely buggy, especially with PHP >=8. Based on #87 it turned out that this busybox's sendmail replaces all\nwith\r\n- except that as from PHP8, all line breaks are already\r\n, so busybox's sendmail makes this\r\r\n. I'm no a C programmer, so my understanding may be off, but it definitely looked like the cause of the original issue to me.You should be able to test PHP's mail() in verbose mode like this:
If you're getting errors similar to that bug report I linked to, then you will probably need to replace sendmail with a compliant sendmail version.
Lastly, I assume
is a typo? It should be just
sendmail_path=/usr/sbin/sendmail -S host.docker.internal:1025I hope this helps and that you're able to debug your issue.
@back-2-95 commented on GitHub (Aug 14, 2023):
Sendmail is at least this container Alpine's BusyBox v1.36.1
gives failed at the end:
@axllent commented on GitHub (Aug 14, 2023):
Your output looks identical to #87 - this is not a Mailpit bug, it looks like the same busybox sendmail bug likely caused by
\r\r\n(which is not valid/compliant).As a work-around for the buggy sendmail, you could set your existing sendmail as such:
The
dos2unixcommand replaces all\r\nwith just\n, which busybox's sendmail then turns back into\r\n- and everything is compliant again.You can test this with:
@back-2-95 commented on GitHub (Aug 14, 2023):
Workaround seems to work, I tested it on a few projects. Problem still persists on projects where we are not the authors of the PHP Docker images used and if they don't support changing sendmail configuration with
PHP_SENDMAIL_PATHenv variable.@axllent commented on GitHub (Aug 15, 2023):
Whilst I understand your issue (not always having control over the docker images used), this is appears to still be an issue with this sendmail implementation, which is sending non-RFC-compliant headers to Mailpit (or any SMTP server for that matter). In my view, Mailpit is doing exactly what is was mean to - it is (among other things) an SMTP testing tool too, and so it isn't accepting a non-compliant SMTP connection.
The problem should be fixed upstream, ie: in busybox's sendmail, which would then resolve the issue everywhere once fixed and rolled out. I have just reported the issue in their bug tracker, so we'll see what happens there and what their response is.
I will still look in the meantime whether there is a work-around for Mailpit (to accept the non-compliant headers), however last time I looked it didn't seem possible, and as I just said, it defeats the point of testing SMTP if it allows non-compliant headers.
@back-2-95 commented on GitHub (Aug 15, 2023):
You mention in #87 alternative sendmail available for Alpine being
msmtp? Is it somewhat drop-in replacement? If so, I could use that in out internal images.@axllent commented on GitHub (Aug 15, 2023):
That was (from memory) a replacement, but not sure about it being "drop-in". But ... before you continue - I have been looking into a working solution. The workaround (I haven't released this yet) will resolve the issue for you, with an option to turn it off. I'm not 100% happy about "fixing" messages by default, but with careful consideration I think that this is the better approach as it's clear that this is a blocker for many developers who use busybox's sendmail implementation in testing.
Most users, like yourself, will just get an error and not understand what the actual problem is, and some major mailservers like postfix already auto-correct this anyway. I expect to have this "feature" released in the next couple of days.
@axllent commented on GitHub (Aug 16, 2023):
I have just released this "fix" in v1.8.2. Please let me know if it resolves your sending error?
@back-2-95 commented on GitHub (Aug 16, 2023):
Just tried it:
It works IF I change the php.ini sendmail setting from
PHP_SENDMAIL_PATH=/usr/sbin/sendmail -S host.docker.internal:1025toPHP_SENDMAIL_PATH=/usr/sbin/sendmail -S host.docker.internal:1025 -t@axllent commented on GitHub (Aug 16, 2023):
Ahh yes, the
-tis required IF your mailer (PHP) doesn't provide the recipients on the commandline when using that sendmail. This is expected behaviour and the default in thephp.ini.Glad it's working!
@back-2-95 commented on GitHub (Aug 16, 2023):
Yes! Thank you for the support, I can now add Mailpit as Mailhog replacement in our tooling and projects just need to add that
-tflag toPHP_SENDMAIL_PATH.