{"id":5796,"date":"2020-09-02T14:05:31","date_gmt":"2020-09-02T08:35:31","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5796"},"modified":"2026-11-16T11:58:11","modified_gmt":"2026-11-16T06:28:11","slug":"setup-postfix-with-mailgun-for-reliable-e-mail-delivery-on-ubuntu","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/setup-postfix-with-mailgun-for-reliable-e-mail-delivery-on-ubuntu\/","title":{"rendered":"Setup Postfix with Mailgun for Reliable Email Delivery on Ubuntu"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date:<\/strong> 02 September 2020<br><strong>Last Updated:<\/strong> 16 November 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Setup Postfix with Mailgun on Ubuntu<\/strong> to configure email delivery through Mailgun as an SMTP relay. Postfix is a Mail Transfer Agent (MTA) responsible for delivering and receiving emails. It is essential for creating a complete mail server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we will explain how to install Postfix, create a Mailgun account, and configure Postfix to send emails through Mailgun.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation Steps<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install Postfix<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Log in to the server using SSH.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As the root user, install Postfix using the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apt-get install postfix<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"684\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2-1024x684.png\" alt=\"Setup Postfix with Mailgun on Ubuntu \u2013 Postfix installation configuration screen.\" class=\"wp-image-13419\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2-1024x684.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2-300x200.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2-768x513.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2-272x182.png 272w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-2.png 1143w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, enter the fully qualified domain name (FQDN) that you want to use for sending and receiving emails.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-3.png\"><img decoding=\"async\" width=\"810\" height=\"603\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-3.png\" alt=\"Postfix Mailgun Configuration \u2013 Postfix setup screen displaying the fully qualified mail domain.\" class=\"wp-image-13420\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-3.png 810w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-3-300x223.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/image-3-768x572.png 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the FQDN is configured, restart the Postfix mail server using the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">service postfix restart<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Sign Up for a Free Mailgun Account<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Mailgun provides powerful APIs that allow you to send, receive, and track emails.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sign up for a Mailgun account using the following link:<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"6pZ1LB9Lm9\"><a href=\"https:\/\/www.mailgun.com\/\" target=\"_blank\" rel=\"noopener\">Transactional Email Delivery Service &amp; API for Developers<\/a><\/blockquote><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"\u201cTransactional Email Delivery Service &amp; API for Developers\u201d \u2014 Transactional Email API Service For Developers | Mailgun\" src=\"https:\/\/www.mailgun.com\/embed\/#?secret=LJ72InpM1E#?secret=6pZ1LB9Lm9\" data-secret=\"6pZ1LB9Lm9\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have signed up, access your Mailgun Control Panel:<\/p>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/mailgun.com\/cp\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Follow these steps to add your domain:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Click the <strong>Domains<\/strong> tab.<\/li>\n\n\n\n<li>Select the <strong>Add Domain<\/strong> button.<\/li>\n\n\n\n<li>Enter your domain name.<\/li>\n\n\n\n<li>Click the <strong>Create Domain<\/strong> button at the bottom of the form.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">This will create your domain in Mailgun.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click the <strong>Domains<\/strong> tab again and select your newly created domain from the list. This will open the details page for your domain.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Configure Postfix to Use Mailgun as a Relay Host<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can find your SMTP password on the domain details page in Mailgun. This password is required when configuring Postfix to send emails through Mailgun.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the Postfix <code>main.cf<\/code> file using the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nano \/etc\/postfix\/main.cf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following configuration at the bottom of the file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">relayhost = smtp.mailgun.org\nsmtp_sasl_auth_enable = yes\nsmtp_sasl_password_maps = static:postmaster@pheonixsolutions.com:password\nsmtp_sasl_security_options = noanonymous<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Replace the following values:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>pheonixsolutions.com<\/code> with your domain name.<\/li>\n\n\n\n<li><code>password<\/code> with the password obtained from the Mailgun Control Panel.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Save your changes and restart Postfix:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">service postfix restart<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your Postfix server will now send emails through Mailgun.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Postfix can be configured with Mailgun to send emails through an external relay host. By installing Postfix, creating a Mailgun account, and configuring the SMTP relay settings, you can enable email delivery through Mailgun on your Ubuntu server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-create-sending-api-for-domain-in-mailgun\/\">How to Create Sending API for Domain in Mailgun<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Official Documentation<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/documentation.mailgun.com\/docs\/mailgun\/user-manual\/smtp-protocol\/smtp-relay\" target=\"_blank\" rel=\"noopener\">Mailgun \u2013 SMTP Relay Configuration<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/documentation.mailgun.com\/docs\/mailgun\/user-manual\/sending-messages\/send-smtp\" target=\"_blank\" rel=\"noopener\">Mailgun \u2013 Sending Messages via SMTP<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.postfix.org\/documentation.html\" target=\"_blank\" rel=\"noopener\">Postfix \u2013 Official Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/ubuntu.com\/server\/docs\" target=\"_blank\" rel=\"noopener\">Ubuntu \u2013 Server Documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Pheonix Solutions Can Help<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Reliable email delivery is essential for business communication, application notifications, and server alerts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/devops-cloud\/\"><strong>Pheonix Solutions<\/strong><\/a> provides DevOps, cloud infrastructure, server administration, and email configuration services to help businesses maintain reliable IT environments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our experts can help you configure SMTP relays, troubleshoot email delivery issues, manage mail servers, and improve server communication.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/contact\"><strong>Contact our experts<\/strong><\/a> to discuss your email infrastructure requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: 02 September 2020Last Updated: 16 November 2026 Introduction Setup Postfix with Mailgun on Ubuntu to configure email delivery [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13427,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[198,171],"class_list":["post-5796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-aws","tag-mailserver","tag-postfix","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1vu","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Postfix-Mailgun-Setup-on-Ubuntu.png","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5796"}],"version-history":[{"count":4,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5796\/revisions"}],"predecessor-version":[{"id":13433,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5796\/revisions\/13433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media\/13427"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}