Linux – Setting up an email proxy server

emaillinuxsmtp

So i have 4 application servers and each one directly connects to an SMTP server to send out the emails. What I want is to have something in the middle that my servers connect through instead, and that middle-ware (?) will be what pushes my emails through to the SMTP server. So this SMTP server will only see emails coming from one source instead of 4.

I am unfamiliar with how this sort of thing works, but It sounds like I need to create my own SMTP server which would accept the incoming requests and send them off to the main SMTP?

I just need something very lightweight and basic as its just going to be these servers accessing it and it will be only have the function of relaying these emails. Any help to get me going in the right direction would be appreciated.

UPDATE

Thanks for the corrections in that what I am looking for is an email relay. There is a reason though I used the work "proxy" and I mistakenly did not explain that clearly.

What I want is the new relay to assume the role of the sender of the email. With a web proxy the user IP is hidden and the traffic appears as though its from the proxy IP. That's what I want for this email relay. My relay IP should appear to be the sender, not the application servers as those should be hidden.

So no matter which application server sends the email, the sender IP should always appear to be the relay I setup. Is that possible?

Best Answer

I can't (yet) comment so I will try to answer the way I understood the question.

It seems you want to place a relay SMTP server in between your 4 app servers and your "final" SMTP server.

If I understood it correctly and if you are using Linux, I would suggest you use postfix configured as a relay for your 4 app servers.

Once installed, postfix offers lots and lots of configuration options in its main config file (usually /etc/postfix/main.cf), but you are very interested in the ones below:

relayhost = <smtp_out_server>
smtpd_client_restrictions = <IPs from your appservers> # only they can connect!

Review the rest of main.cf to ensure sane configs (when I did a similar work, all defaults for small traffic were OK) and you should be good to go.

If your relayhost needs a user/password authentication, then you will need to configure SASL authentication. In this case, follow this additional steps:

1) Ensure sasl2 and sasl2-plug-plain packages are installed (generally yes)

2) setup an /etc/postfix/sasl_passwd file with the following info: <smtp_server> <smtp_user>:<password> (note the blank space between and the rest of the line)

3) chmod 600 sasl_passwd to make it as safe as possible;

4) run postmap hash:/etc/postfix/sasl_passwd to generate the password map;

5) Add the following to main.cf

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =

6) reload postfix with service postfix reload

... and you should be good to go (again).

Hope this helps,

UPDATE

If I understood your update correctly, what you want to do is answered by this other SF question: Remove/hide client sender ip from postfix?

HTH.