How to send email via HAProxy

Hello everyone,
I am a newbie for HAProxy, and tried to install 3 SMTP servers with postfix.
Finally, it seems that I got the correct result with telnet testing.
It replied like below when I used telnet on terminal

$ telnet x.x.x.1 25
Trying x.x.x.1…
Connected to x.x.x.1.
Escape chracter is ‘^]’
220 mail1.example.com ESMTP Postfix (Ubuntu)

$ telnet x.x.x.1 25
Trying x.x.x.1…
Connected to x.x.x.1.
Escape chracter is ‘^]’
220 mail2.example.com ESMTP Postfix (Ubuntu)

$ telnet x.x.x.1 25
Trying x.x.x.1…
Connected to x.x.x.1.
Escape chracter is ‘^]’
220 mail3.example.com ESMTP Postfix (Ubuntu)

By the way, my concern is how to send real email from my pc via HAProxy.
Any suggestion or help would be appreciated.
Regards,
Jason.

I’m not quite sure what you are trying to achieve here…

Do you want to load-balance the three mail servers? (I would assume so in the rest of my reply.)

Basically you just need to define a TCP fronted and backend (with three servers), like so:


frontend smtp-frontend
    mode tcp
    bind ipv4@0.0.0.0:25
    bind ipv4@0.0.0.0:587
    bind ipv4@0.0.0.0:465 ssl crt /etc/ssl/private/smtp.pem verify none
    default_backend smtp-backend

backend smtp-backend
    mode tcp
    server server-1 ipv4@172.0.0.1:25 maxconn 8 send-proxy check
    server server-2 ipv4@172.0.0.2:25 maxconn 8 send-proxy check
    server server-3 ipv4@172.0.0.3:25 maxconn 8 send-proxy check

Please note the send-proxy option to server, which sends the PROXY header with the original IP of the client. To make this work in PostFix you need set the following in /etc/postfix/main.cf:

smtpd_upstream_proxy_protocol = haproxy
proxy_interfaces = 1.2.3.4 # the "public" IP of HAProxy, not sure if this line is actually needed

Thanks for you reply @ciprian.craciun
I already defined HAProxy and Postfix configuration file, and that’s why I was able to get the correct response with telnet command.
So HAProxy correctly connected with Postfix, but I want to send email.
Another say, what kind of command or tool should I use to sending email to my gmail or hotmail via HAProxy?
let’s say that the HAProxy server host name is smtp.example.com
How to send email to this HAProxy from my PC, so that the email should be sent through 3 Postfix server.

Thanks.

Please advise me anything, hope to hear back from good news soon.

If you actually want to send emails through you need to use an SMTP client. There are countless mail clients from Thunderbird to Outlook, or even command line ones like msmtp.

From HAProxy’s standpoint there is nothing more to be done. Now it’s a matter of correctly configuring Postfix and your mail clients.