mjl- / mox

modern full-featured open source secure mail server for low-maintenance self-hosted email
https://www.xmox.nl
MIT License
3.36k stars 89 forks source link

How to allow my local script to send email without authentication? #155

Closed manaus0xff closed 2 months ago

manaus0xff commented 2 months ago

Let's say, I have a Python script on the same machine where Mox is run. Is there a way to allow a script to send email, of any account, via Mox without login-password authentication? Postfix allows this.

lmeunier commented 2 months ago

Not with mox. mox requires authentication for mail submission. But, you can use something like msmtp to deliver mail with mox (msmtp will handle auth with mox) from your Python script, provided that your script use the sendmail command provided by msmtp.

mjl- commented 2 months ago

You can also setup mox as /usr/sbin/sendmail, see https://pkg.go.dev/github.com/mjl-/mox#hdr-mox_sendmail. The mox account to send as must then be configured in /etc/moxsubmit.conf.

What do you have in mind with "of any account"? Allow the mox user to send a message as any account? Or maybe you want to relate unix (system) accounts to mox accounts? That's not currently possible. In the future, we could change mox to serve a unix domain socket (like its current "ctl" socket), where scripts could write an email message to be delivered. Mox then retrieves the uid of the other side (SO_PEERCRED). The mox admin must then configure the unix account that belongs to a mox account (this would require new config options in the mox config files).

manaus0xff commented 2 months ago

What do you have in mind with "of any account"?

Allow a script to send a message of any account. My intention is to avoid authentication altogether if both Mox and a script are on the same machine.

mjl- commented 2 months ago

ok, if i'm understand this correctly, you have a mox on a machine, configured with multiple accounts. and the script on the same machine wants to send using any of those mox accounts. i suppose you want to match a mox account based on the address of the "from" header of the message? or do you still want to pass the account name explicitly when submitting a message? i'm wondering what the use case is. why the need to send messages for any account instead of a specific one? e.g. just one, possibly configured with multiple email addresses to send from.

either way, i see two approaches for implementing this: 1. serve a unix domain socket to submit messages on. 2. make mox monitor a queue directory anyone can place files that mox can picks up for delivery. both cases would "authenticate" the request based on the uid who connected to the socket or wrote the file. mox would need a config option to match unix uids to mox accounts. the first option seems cleaner to me, but probably requires a very simple protocol (could be smtp over unix domain socket if you want to preserve mailfrom/rcptto addressing, or a simpler "write" of a message with addressees in headers). the second option seems less attractive: there is no clean mechanism for parameters or feedback. (i have a vague recollection of mail servers with setgid tools that write to a queue directory). a sendmail-variant can be written that implements the first option.

question: how does postfix do this?

manaus0xff commented 2 months ago

question: how does postfix do this?

localdomain

Alright, I'll use authentication