[GH-ISSUE #310] Allow the use of an environment variable to set the sendmail smtp address #204

Closed
opened 2026-03-15 13:10:23 +03:00 by kerem · 9 comments
Owner

Originally created by @brammeleman on GitHub (Jun 7, 2024).
Original GitHub issue: https://github.com/axllent/mailpit/issues/310

Use case:
I'm testing software that mails to localhost:25 in production but in my test environment, I want to deliver to the mailpit container on port 1025.

Setting the MH_SENDMAIL_SMTP_ADDR to mailpit:1025 would enable me to leave the sendmail-using software identical.

Originally created by @brammeleman on GitHub (Jun 7, 2024). Original GitHub issue: https://github.com/axllent/mailpit/issues/310 Use case: I'm testing software that mails to localhost:25 in production but in my test environment, I want to deliver to the mailpit container on port 1025. Setting the `MH_SENDMAIL_SMTP_ADDR` to `mailpit:1025` would enable me to leave the sendmail-using software identical.
kerem closed this issue 2026-03-15 13:10:28 +03:00
Author
Owner

@axllent commented on GitHub (Jun 7, 2024):

If I understand correctly, you are wanting to use Mailpit's sendmail to route to another type of SMTP server eg: postfix or something (please confirm)?

<!-- gh-comment-id:2155459157 --> @axllent commented on GitHub (Jun 7, 2024): If I understand correctly, you are wanting to use Mailpit's sendmail to route to another type of SMTP server eg: postfix or something (please confirm)?
Author
Owner

@brammeleman commented on GitHub (Jun 10, 2024):

Mmm, I think I was a bit confused here. As a former mailhog (which shipped mhsendmail) user, I assumed the mailpit sendmail binary was actually talking smtp to mailpit. But since sendmail is just another name/command of the mailpit binary itself, it doesn't make sense to have this environment variable.

Sorry for this unnecessary issue! please close this issue..

ps: In the meantime, I'm using mailpit in the same container as my application for testing.

<!-- gh-comment-id:2157903309 --> @brammeleman commented on GitHub (Jun 10, 2024): Mmm, I think I was a bit confused here. As a former mailhog (which shipped `mhsendmail`) user, I assumed the mailpit sendmail binary was actually talking smtp to mailpit. But since sendmail is just another name/command of the mailpit binary itself, it doesn't make sense to have this environment variable. Sorry for this unnecessary issue! please close this issue.. ps: In the meantime, I'm using mailpit in the same container as my application for testing.
Author
Owner

@axllent commented on GitHub (Jun 10, 2024):

Well, you're not wrong. Mailpit's sendmail implementation does use regular SMTP to talk to Mailpit, so it will technically work with any SMTP server. It is basically just another sendmail port (of sorts), as are the other dozen or so sendmail implementations commonly installed is systems. I'm just saying that this one was created specifically to communicate with Mailpit, and isn't extensively tested on anything other than Mailpit, so your mileage may vary.

<!-- gh-comment-id:2157981832 --> @axllent commented on GitHub (Jun 10, 2024): Well, you're not wrong. Mailpit's sendmail implementation does use regular SMTP to talk to Mailpit, so it will technically work with any SMTP server. It is basically just another sendmail port (of sorts), as are the other dozen or so sendmail implementations commonly installed is systems. I'm just saying that this one was created specifically to communicate with Mailpit, and isn't extensively tested on anything other than Mailpit, so your mileage may vary.
Author
Owner

@axllent commented on GitHub (Jun 10, 2024):

So to further my previous message, it sounds like this is exactly what you want to do - use Mailpit's sendmail to relay messages directly to a third party SMTP server. Provided that SMTP server does not require authentication, it should technically work. If this is what you want to achieve, then I can add support for an environment variable. Is this what you are still wanting after my explanation about its intended purpose?

<!-- gh-comment-id:2158001128 --> @axllent commented on GitHub (Jun 10, 2024): So to further my previous message, it sounds like this is exactly what you want to do - use Mailpit's sendmail to relay messages directly to a third party SMTP server. Provided that SMTP server does not require authentication, it should technically work. If this is what you want to achieve, then I can add support for an environment variable. Is this what you are still wanting after my explanation about its intended purpose?
Author
Owner

@brammeleman commented on GitHub (Jun 10, 2024):

Let me explain my use case:
In one container:

  • I have code that calls sendmail in my dev-container
  • This container has the mailhog sendmail (go install github.com/mailhog/mhsendmail@9e70164f299c9e06af61402e636f5bbdf03e7dbb/usr/bin/sendmail ) as /usr/sbin/sendmail
  • the environment variable MH_SENDMAIL_SMTP_ADDR=mail:1025
  • all calls to sendmail result in an attempt to deliver mail to mail:1025 without any modifications to applications/scripts.

The mail container runs mailpit.

<!-- gh-comment-id:2158085648 --> @brammeleman commented on GitHub (Jun 10, 2024): Let me explain my use case: In one container: - I have code that calls sendmail in my dev-container - This container has the mailhog sendmail (`go install github.com/mailhog/mhsendmail@9e70164f299c9e06af61402e636f5bbdf03e7dbb/usr/bin/sendmail` ) as /usr/sbin/sendmail - the environment variable `MH_SENDMAIL_SMTP_ADDR=mail:1025` - all calls to sendmail result in an attempt to deliver mail to mail:1025 without any modifications to applications/scripts. The `mail` container runs mailpit.
Author
Owner

@axllent commented on GitHub (Jun 11, 2024):

So you're wanting to do this with Mailpit's sendmail too. There is already an undocumented MP_SENDMAIL_SMTP_ADDR (eg: MP_SENDMAIL_SMTP_ADDR=mail:1025) variable you should be able to use. Please confirm if this works for you?

<!-- gh-comment-id:2159598005 --> @axllent commented on GitHub (Jun 11, 2024): So you're wanting to do this with Mailpit's sendmail too. There is already an undocumented `MP_SENDMAIL_SMTP_ADDR` (eg: `MP_SENDMAIL_SMTP_ADDR=mail:1025`) [variable](https://github.com/axllent/mailpit/blob/develop/sendmail/cmd/cmd.go#L71-L73) you should be able to use. Please confirm if this works for you?
Author
Owner

@brammeleman commented on GitHub (Jun 11, 2024):

Great! This works and is exactly what I need ;-)

MP_SENDMAIL_SMTP_ADDR=mailpit:1025 sendmail bla@example.com < mail

Could you add it to https://mailpit.axllent.org/docs/configuration/runtime-options/ ?

<!-- gh-comment-id:2160574218 --> @brammeleman commented on GitHub (Jun 11, 2024): Great! This works and is exactly what I need ;-) ``` MP_SENDMAIL_SMTP_ADDR=mailpit:1025 sendmail bla@example.com < mail ``` Could you add it to https://mailpit.axllent.org/docs/configuration/runtime-options/ ?
Author
Owner

@axllent commented on GitHub (Jun 12, 2024):

I've added it now to the sendmail page rather than the runtime options as the runtime options are "server related" flags & environment variables 👍 Thanks for testing / confirming!

<!-- gh-comment-id:2162045483 --> @axllent commented on GitHub (Jun 12, 2024): I've added it now to the [sendmail page](https://mailpit.axllent.org/docs/install/sendmail/#settings-via-the-environment) rather than the runtime options as the runtime options are "server related" flags & environment variables :+1: Thanks for testing / confirming!
Author
Owner

@brammeleman commented on GitHub (Jun 12, 2024):

Many thanks!

<!-- gh-comment-id:2162303572 --> @brammeleman commented on GitHub (Jun 12, 2024): Many thanks!
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/mailpit#204
No description provided.