Send mails from one VM when postfix is on the other VM in the same server

In reality the answer for the services VM can be...it depends. If it is applications, you can point them to email:25/TCP.

If we are talking about daemons/services, you configure both in the services and http-proxy VMs:

  • in exim, as smarthost email

  • a simple postfix with a relayhost configured to point to the email host. As in, in main.cf:

    relayhost = email
    
  • Or, you can configure a lightweight SMTP forwarder as ssmtp, that just forwards emails send by the sendmail compatible API.

In ssmtp.conf you define then:

hostname=FQDN  # full DNS name of your server where `ssmtp` is installed
mailhub=email  # name or IP address of your central SMTP server

sSMTP - Simple SMTP

sSMTP is a simple MTA to deliver mail from a computer to a mail hub (SMTP server). sSMTP is simple and lightweight, there are no daemons or anything hogging up CPU; Just sSMTP. Unlike Exim4, sSMTP does not receive mail, expand aliases, or manage a queue.


One solution is to configure a post fix null client on the services machine.

This way the postfix on the services machine will forward mails to the postfix on the email machine.

How:

1- install postfix on services machine :

$ yum install postfix

2- Configure services machine postfix to relay mails to the email machine, keep the brackets on if your using a domain name.

EDIT:

The use of barckets avoids MX record lookup from dns.

$ postconf -e "relayhost=[email.example.com]"

3- Let the Postfix mail server on the services machine listen only on the loopback interface for emails to deliver.

postconf -e "inet_interfaces=loopback-only"

4- Change the configuration of the null client so that mails originating from the 127.0.0.0/8 IPv4 network and the [::1]/128 IPv6 network are forwarded to the relay host by the local null client.

$ postconf -e "mynetworks=127.0.0.0/8 [::1]/128"

5- Configure Postfix so all outgoing mails have their sender domain rewritten to the email machine domain email.example.com.

postconf -e "myorigin=email.example.com"

EDIT:

No brackets here because this is just a string that is going to replace your services machine sender domain name.

6- Restart the local postfix null client.

$ systemctl restart postfix