Reputation: 8555
I'm running a bunch of Debian/Ubuntu servers, with one core, main server that all the other web servers connect to. Right now though, when our core server sends an email (like someone sending an email through our administrative web GUI), the first "Received:" header lists the address to our main server, which we want to avoid.
So my plan was to setup a way to send the email through the server it should really be coming from. So when we send an email from the software at www.backend.com, I would like the headers to reflect www.frontend.com. I tried looking up SMTP proxy for Ubuntu but didn't find too much, except to look for something called MTAs.
I played around with nullmailer and msmtp, but I can't seem to get either to work the way I'm expecting, e.g. set up the SMTP credentials on www.backend.com for this account to point to www.frontend.com and have the front end server connect to our email provider. Is what I'm trying to do possible?
EDIT TL;DR
I keep trying to set up SMTP relay servers, but I can't connect to my postfix SMTP server remotely. How do I setup a simple email relay server on Debian Ubuntu? Not sure if that's even the right term, because there seems to be hundreds of articles explaining how but I cannot get a single one to work
Upvotes: 1
Views: 2034
Reputation: 13495
Your MTA is postfix, and you want to use it twice; as an INTRANET host and an edge relay. So the first step is not to remove the received header, but to make sure the relay is allowed and occurs which will add the "frontend" relay in the headers. Once relaying is functioning, the relay can remove or replace header lines.
On the relay (FRONTEND) docs#relay_from
mynetworks = 127.0.0.0/8 IP_OF_BACKEND/32 ...others?
On the sender (BACKEND) relayhost
relayhost = [www.frontend.com]
For simple filters, header_checks is sufficient.
header_checks = pcre:/etc/postfix/header_checks
(pcre - make sure postfix-pcre support is installed, or follow the POSIX regex debugging in the next link.)
It is generally best to sanitize the header rather than remove it, so example contents of that file sanitizing it is here, though it should be matched to only rewrite received headers from backend
instead of all hosts .*
.
So after examining the real received headers you want to replace and deciding which part(s) to keep as regex groups, your substitution might be something simple like this:
/^Received: from www.backend.com.*id\s(\w+).*/
REPLACE Received: from [127.0.0.1] (localhost [127.0.0.1]) with SMTP id $1
Removing the received header is essentially the same, but can use the IGNORE
action instead of REPLACE
and requires a simpler regex as there is no substitute header to build. However, removing headers is more likely to cause issues as you add Milters, etc for later requirements.
Upvotes: 1