Yes, that should do the trick.
The only problem that you could face is the certificate validation in
PHPMailer: if you connect to `locahost` using a TLS connection, unless
your certificate presents `localhost` as a CN (or a SAN), there's
chances that the client refuses to establish the connection (I don't
remember if certificate validation is enabled by default in PHPMailer).
If you don't want to bypass certificate validation, one possible way to
overcome this issue is to set an entry in your chroot's `/etc/hosts`
pointing your certificate's CN to `127.0.0.1`, or include `localhost` in
your certificate SANs. And if your certificate is self signed, you'll
have to manually accept it.
Regards.
Le 04/04/18 à 14:15, Markus Rosjat a écrit :
Hi,
I will answer in the text below :)
Am 04.04.2018 um 13:52 schrieb Christophe Simon:
Hello,
I'd say that all depends on the function/library you're using in your
PHP application to send mails.
The `mail()` command, for instance, uses the `sendmail` binary to
directly ingest your message in your local mail spool, and thus does
not require any authentication. The mail is sent on behalf of the
identity your web server runs under. There's options to set the
appropriate sender in the message headers, obviously.
no we don't want to use binary in chroot, that somehow feels just wrong :)
If you're using a library such as `PHPMailer`, you'll want to use the
SMTP protocol, either locally (on lo0) (1), or remotely (on your mail
provider's SMTP service) (2).
since it will be WP (i know ...) it has PHPMailer and it should be able
to send with SMTP Protocol.
It's up to you to define if you want authentication on the loopback
port (but that's better to do so).
If you're using your local MTA to send emails (1), either using the
SMTP protocol on lo0 or the `sendmail` binary, there's chances you'll
want to use a relay host to avoid being blacklisted by your recipients
servers (or you should take care to have a resolvable public IP with
correct SPF configured in your DNS). Such a configuration has been
very well illustrated by Michael below.
I have set up the local smtpd to relay mails from local connections so
it's only listen on lo0 but hey PHPMailer will connect on lo0 and can be
abused still if the WP arround it allows it. I basically force the user
to use something like recaptcha but even then I would like to do
something with authentication thought.
for me I short example would be helpful for now I basically let a script
run once an hour to check if the maillog shows somewhat strange traffic
to the relay.
is enabling auth on lo0 simply this ?
pki hostname /path/to/cert
pki hostname /path/to/key
table aliases file:/etc/mail/aliases
table secrets file:/etc/mail/secrets
listen on lo0 port submission tls auth
accept for any relay via tls+auth://relaycred@relayhost:587 auth <secrets>
And then I can just setup the PHPMailer to use submission port on
localhost with some credentials?
Regards