{"id":362,"date":"2025-11-29T12:20:13","date_gmt":"2025-11-29T11:20:13","guid":{"rendered":"https:\/\/techbygiusi.com\/?p=362"},"modified":"2026-01-03T23:53:09","modified_gmt":"2026-01-03T22:53:09","slug":"how-to-configure-postfix-for-smtp-relay","status":"publish","type":"post","link":"https:\/\/techbygiusi.com\/index.php\/guide\/how-to-configure-postfix-for-smtp-relay\/","title":{"rendered":"How to configure Postfix for SMTP-Relay"},"content":{"rendered":"\n<p>For many years, Microsoft Exchange on-premises served as the central mail hub in countless environments. Applications, scanners, monitoring systems, and legacy tools all relied on it for outgoing email. But with Exchange Server now essentially retired for most modern deployments, many administrators are looking for a stable alternative that still fits the old-school, dependable way of doing things.<\/p>\n\n\n\n<p>A lightweight, local SMTP relay based on Postfix offers exactly that. It\u2019s simple, time-tested, and integrates smoothly with Microsoft Exchange Connectors. Below is a straightforward guide to setting up such a relay on Ubuntu.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Legend<\/h6>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#Installing-Postfix\" data-type=\"internal\" data-id=\"#Installing-Postfix\">Installing Postfix<\/a><\/li>\n\n\n\n<li><a href=\"#Adjusting-the-Postfix-Configuration\" data-type=\"internal\" data-id=\"#Adjusting-the-Postfix-Configuration\">Adjusting the Postfix Configuration<\/a><\/li>\n\n\n\n<li><a href=\"#Checking-Postfix-Status-and-Logs\" data-type=\"internal\" data-id=\"#Checking-Postfix-Status-and-Logs\">Checking Postfix Status and Logs<\/a><\/li>\n\n\n\n<li><a href=\"#Other-recommendations\" data-type=\"internal\" data-id=\"#Other-recommendations\">Other recommendations<\/a><\/li>\n<\/ul>\n\n\n\n<h6 class=\"wp-block-heading\" id=\"Installing-Postfix\">Installing Postfix<\/h6>\n\n\n\n<p>Start with a clean Ubuntu Server and install Postfix:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install postfix<\/code><\/pre>\n\n\n\n<p>During installation, choose <strong>\u201cSatellite System\u201d<\/strong> when prompted.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"#lb-1-5ab99b7d\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"578\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-6-1024x578.png\" alt=\"\" class=\"wp-image-372\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-6-1024x578.png 1024w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-6-300x169.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-6-768x434.png 768w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-6.png 1156w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n\n<p>Here you can use your server name or any random name for your SMTP relay. The name does not matter in this case.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"#lb-2-0557690c\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"175\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-12-1024x175.png\" alt=\"\" class=\"wp-image-381\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-12-1024x175.png 1024w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-12-300x51.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-12-768x131.png 768w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-12-1536x263.png 1536w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-12.png 1882w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n\n<p>In the next step, you can enter a valid domain name. If you have installed the server in a DMZ without domain access, you can leave it as it is.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"#lb-3-dd946eaf\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"203\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-8-1024x203.png\" alt=\"\" class=\"wp-image-374\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-8-1024x203.png 1024w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-8-300x59.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-8-768x152.png 768w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-8-1536x304.png 1536w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-8.png 1809w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n\n<p>Accept the installation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"#lb-4-a8bfef0d\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"184\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-13-1024x184.png\" alt=\"\" class=\"wp-image-382\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-13-1024x184.png 1024w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-13-300x54.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-13-768x138.png 768w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-13-1536x277.png 1536w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-13.png 1621w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n\n<h6 class=\"wp-block-heading\" id=\"Adjusting-the-Postfix-Configuration\">Adjusting the Postfix Configuration<\/h6>\n\n\n\n<p>Move into the configuration directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/etc\/postfix<\/code><\/pre>\n\n\n\n<p>Open the <code>main.cf<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano main.cf<\/code><\/pre>\n\n\n\n<p>The following lines in your <code>main.cf<\/code> file are essential for ensuring that your SMTP relay behaves correctly, uses TLS where needed, and communicates properly with Exchange Online. These settings define how Postfix identifies itself, handles incoming connections, applies TLS, and relays outgoing mail.<\/p>\n\n\n\n<p><strong>Hostname<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>myhostname = smpt-relay   # Hostname of your SMTP relay<\/code><\/pre>\n\n\n\n<p>This defines the server name Postfix uses when communicating with other mail systems.<\/p>\n\n\n\n<p><strong>Exchange Online (EOP) relay target<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>relayhost = [company02e.mail.protection.outlook.com]:25<\/code><\/pre>\n\n\n\n<p>This is your Exchange Online tenant\u2019s relay endpoint. Mail that reaches this server will be forwarded to Microsoft 365.<br>You can obtain the correct hostname from the <strong>Microsoft 365 Admin Center \u2192 Domains \u2192 DNS Records<\/strong>.<\/p>\n\n\n\n<p><strong>Allowed IPs or subnets<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mynetworks = 127.0.0.0\/8 [::ffff:127.0.0.0]\/104 [::1]\/128 172.25.10.10\/24<\/code><\/pre>\n\n\n\n<p>Only systems listed here are allowed to submit mail to your relay. This is your primary security control, so keep the list as small as possible.<\/p>\n\n\n\n<p>Here is a solid, traditional configuration that establishes the server as a relay for approved systems in your network:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtpd_banner = $myhostname ESMTP $mail_name\nbiff = no\nappend_dot_mydomain = no\nreadme_directory = no\ncompatibility_level = 3.6\n\n# TLS\nsmtpd_tls_cert_file=\/etc\/ssl\/certs\/ssl-cert-snakeoil.pem\nsmtpd_tls_key_file=\/etc\/ssl\/private\/ssl-cert-snakeoil.key\nsmtpd_tls_security_level=may\n\nsmtp_tls_CApath=\/etc\/ssl\/certs\nsmtp_tls_security_level=may\nsmtp_tls_session_cache_database = btree:${data_directory}\/smtp_scache\n\nsmtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination\n\nmyhostname = smpt-relay #hostname of smtp-relay\n\nalias_maps = hash:\/etc\/aliases\nalias_database = hash:\/etc\/aliases\n\n# Your Exchange Online tenant hostname (EOP)\nrelayhost = [company02e.mail.protection.outlook.com]:25\n\nmynetworks = 127.0.0.0\/8 [::ffff:127.0.0.0]\/104 [::1]\/128 172.25.10.10\/24\n\nmailbox_size_limit = 0\nrecipient_delimiter = +\ninet_interfaces = all\ninet_protocols = all\n\nsmtp_sasl_auth_enable = no<\/code><\/pre>\n\n\n\n<p>Reboot the server to ensure all services come up cleanly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo reboot<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\" id=\"Checking-Postfix-Status-and-Logs\">Checking Postfix Status and Logs<\/h6>\n\n\n\n<p>After reboot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status postfix<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"#lb-5-9a0c4ae3\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"205\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-14.png\" alt=\"\" class=\"wp-image-383\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-14.png 800w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-14-300x77.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-14-768x197.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\"><\/a><\/figure>\n\n\n\n<p>For live log monitoring:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -f \/var\/log\/mail.log<\/code><\/pre>\n\n\n\n<p>In this log file you can see service problems, but also messages that were received and successfully sent:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"#lb-6-2994c361\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"78\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-4-1024x78.png\" alt=\"\" class=\"wp-image-389\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-4-1024x78.png 1024w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-4-300x23.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-4-768x59.png 768w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-4-1536x117.png 1536w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-4-2048x157.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n\n\n\n<h6 class=\"wp-block-heading\">Testing the SMTP Relay<\/h6>\n\n\n\n<p>From an allowed server in your network, you can send a test email using PowerShell:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$EmailParams = @{\n    From = \"test@test.test\"\n    To = \"test@test.test\"\n    Subject = \"Test Email\"\n    Body = \"Test Email for SMTP relay testing\"\n    SmtpServer = \"&lt;IP or DNS name of your relay&gt;\"\n    Port = 25\n}\n\nSend-MailMessage @EmailParams<\/code><\/pre>\n\n\n\n<p>If the message arrives and the logs look clean, your relay is working as intended.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Configuring Static Network Settings (Optional)<\/h6>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/netplan\/*.yaml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>network:\n  version: 2\n  ethernets:\n    ens33:\n      dhcp4: false\n      addresses:\n        - 10.10.0.10\/24\n      routes:\n        - to: default\n          via: 10.10.0.1\n      nameservers:\n        addresses:\n          - 100.100.100.100\n          - 1.1.1.1<\/code><\/pre>\n\n\n\n<p>Apply changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo netplan try<\/code><\/pre>\n\n\n\n<p>Press <code>ENTER<\/code> to apply the new network configuartion<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"#lb-7-4000f35b\" class=\"lb-thumb\" aria-label=\"Bild vergr\u00f6\u00dfern\"><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"168\" src=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-15.png\" alt=\"\" class=\"wp-image-384\" srcset=\"https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-15.png 796w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-15-300x63.png 300w, https:\/\/techbygiusi.com\/wp-content\/uploads\/2025\/11\/image-15-768x162.png 768w\" sizes=\"auto, (max-width: 796px) 100vw, 796px\"><\/a><\/figure>\n\n\n\n<h6 class=\"wp-block-heading\" id=\"Other-recommendations\">Other recommendations<\/h6>\n\n\n\n<p>A quick reminder regarding the public IP address:<br>Your SMTP relay server only needs the ability to communicate with the internet <strong>using a fixed public IP<\/strong>. It does <strong>not<\/strong> need to be directly reachable <em>from<\/em> the internet on that address. Inside your network, all relevant systems, applications, and services should send their mail to the relay server via its <strong>internal IP address<\/strong>, just as it has always been done in well-structured environments.<\/p>\n\n\n\n<p>If you make changes to <code>\/etc\/postfix\/main.cf<\/code>, it\u2019s good practice to validate and reload the configuration in the classic, reliable way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo postfix check<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo postfix reload<\/code><\/pre>\n\n\n\n<p>This ensures Postfix picks up your adjustments without requiring a full restart.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For many years, Microsoft Exchange on-premises served as the central mail hub in countless environments. Applications, scanners, monitoring systems, and legacy tools all relied on it for outgoing email. But with Exchange Server now essentially retired for most modern deployments, many administrators are looking for a stable alternative that still fits the old-school, dependable way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[12,28],"class_list":["post-362","post","type-post","status-publish","format-standard","hentry","category-guide","tag-linux","tag-postfix"],"_links":{"self":[{"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/comments?post=362"}],"version-history":[{"count":9,"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/posts\/362\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/media?parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/categories?post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techbygiusi.com\/index.php\/wp-json\/wp\/v2\/tags?post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}