2.3. Configuring Postfix to forward all emails to a mail relay


If you want to forward all email to a mail relay, you can configure Postfix server as a null client. In this configuration Postfix only forwards mail to a different mail server and is not capable of receiving mail.

Prerequisites

  • You have the root access.
  • You have the postfix package installed on your server.
  • You have the IP address or hostname of the relay host to which you want to forward emails.

Procedure

  1. To prevent Postfix from accepting any local email delivery and making it a null client, edit the /etc/postfix/main.cf file and make the following changes:

    1. Configure Postfix to forward all email by setting the mydestination parameter equal to an empty value:

      mydestination =

      In this configuration the Postfix server is not a destination for any email and acts as a null client.

    2. Specify the mail relay server that receives the email from your null client:

      relayhost = [<ip_address_or_hostname>]

      The relay host is responsible for the mail delivery. Enclose <ip_address_or_hostname> in square brackets.

    3. Configure the Postfix mail server to listen only on the loopback interface for emails to deliver:

      inet_interfaces = loopback-only
    4. If you want Postfix to rewrite the sender domain of all outgoing emails to the company domain of your relay mail server, set:

      myorigin = relay.example.com
    5. To disable the local mail delivery, add the following directive at the end of the configuration file:

      local_transport = error: local delivery disabled
    6. Add the mynetworks parameter so that Postfix forwards email from the local system originating from the 127.0.0.0/8 IPv4 network and the [::1]/128 IPv6 network to the mail relay server:

      mynetworks = 127.0.0.0/8, [::1]/128
  2. Verify if the Postfix configuration in the main.cf file is correct:

    # postfix check
  3. Restart the postfix service to apply the changes:

    # systemctl restart postfix

Verification

  • Verify that the email communication is forwarded to the mail relay:

    # echo "This is a test message" | mail -s <subject> <user@example.com>

Troubleshooting

  • In case of errors, check the /var/log/maillog file.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部