habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Easy Install Postfix Ubuntu 20.04

2 min read

Easy-Install-Postfix-Ubuntu-20.04

Hi Dude, today i will post simple article about install postfix Ubuntu 20.04. Ok lets go. Postfix is open source mail transport agent with many feature.

#1. Setup Hostname Server

In this server, im using server name smtp.habibza.in. Just run simply command like this.

hostnamectl set-hostname smtp.habibza.in

After that, jump to /etc/hosts and edit

#vim /etc/host

127.0.0.1 localhost
103.223.224.124 smtp.habibza.in smtp

Reboot for a while to make sure the host has changed perfectly.

#2. Install Postfix in Ubuntu 20.04

In ubuntu server, run the following command below.

sudo apt-get update
sudo apt-get install postfix -y

By default, will appear conversation below. We will be asked to select a type for mail configuration. Select “Internet Site”.

Install Postfix Ubuntu 20
  • No configuration: The installation process will not configure any parameters.
  • Internet Site: Setup Postfix for sending emails to other MTAs and receiving email from other MTAs.
  • Internet with smarthost: Setup postfix to receive email from other MTAs, but using another smart host to relay emails to the recipient.
  • Satellite system: Setup smart host for sending and receiving email.
  • Local only: Setup emails are transmitted only between local user accounts.

Press OK. Input hostname full FQDN.

Input Server Hostname

After finish installed, Postfix will be automatically started and a /etc/postfix/main.cf file will be generated.

See also  Testing and Check Verified Expiration SSL from terminal

#3.Check status Postfix.

systemctl status postfix

Check binary postfix installed.

dpkg -L postfix | grep /usr/sbin/

Output:

/usr/sbin/postalias
/usr/sbin/postcat
/usr/sbin/postconf
/usr/sbin/postdrop
/usr/sbin/postfix
/usr/sbin/postfix-add-filter
/usr/sbin/postfix-add-policy
/usr/sbin/postkick
/usr/sbin/postlock
/usr/sbin/postlog
/usr/sbin/postmap
/usr/sbin/postmulti
/usr/sbin/postqueue
/usr/sbin/postsuper
/usr/sbin/posttls-finger
/usr/sbin/qmqp-sink
/usr/sbin/qmqp-source
/usr/sbin/qshape
/usr/sbin/rmail
/usr/sbin/sendmail
/usr/sbin/smtp-sink
/usr/sbin/smtp-source

#4. Check Allow TCP Port 25 (inbound) in Firewall.

We have to open port 25 TCP incoming in firewall. (If we activated firewall UFW in server).

sudo ufw allow 25/tcp

#5. Check Port 25 Outbound.

Simply way to check port 25 outbound is using telnet. We use telnet port 25 to other server mail, like google gmail mx.

sudo apt install telnet
telnet gmail-smtp-in.l.google.com 25

If it’s not blocked, you would see messages like below.

Trying 74.125.68.26...
Connected to gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP y22si1641751pll.208 - gsmtp

If port 25 (outbound) is blocked or something worng, you would see something like:

Trying 2607:f8b0:400e:c06::1a...
Trying 74.125.195.27...
telnet: Unable to connect to remote host: Connection timed out.

#6. Setting Postfix and Tune it.

By default, Postfix SMTP server uses the OS’s hostname.

Find the myhostname parameter and set mail.yourdomain.com as the value. It’s not recommended to use the apex domain yourdomain.com as myhostname.

myhostname = smtp.habibza.in
sudo systemctl restart postfix

#7. Creating Email Alias.

sudo nano /etc/aliases

By default, there are only two lines in this file.

# See man 5 aliases for format
postmaster: root

The first line is a comment. Normally we don’t use the root email address. So you can add the following line. Replace username with your real username.

root:   username

This way, emails for [email protected] will be delivered to [email protected]. Now you can save and close the file. Then rebuild the alias database with the newaliases command

sudo newaliases

#8. Using IPv4 Only

By default, Postfix uses both IPv4 and IPv6 protocols, as can been seen with:

postconf inet_protocols

Output:

inet_protocols = all

If your mail server doesn’t have a public IPv6 address, it’s better to disable IPv6 in Postfix to prevent unnecessary IPv6 connections. Simply run the following command to disable IPv6 in Postfix.

sudo postconf -e "inet_protocols = ipv4"

Then restart Postfix.

sudo systemctl restart postfix

#9. Increase Attachment Size Limit

By default, the attachment cannot be larger than 10MB, which is indicated by the message_size_limit parameter.

postconf | grep message_size_limit

Output:

message_size_limit = 10240000

This parameter defines the size limit for emails originating from your own mail server and for emails coming to your mail server.

See also  Install Zimbra 8.8.15 in Ubuntu 20.04 (Part 2)

To allow attachment of 50MB in size, run the following command.

sudo postconf -e message_size_limit=52428800

message_size_limit=52428800 thats mean maximum size of email is 50 mb.

#10. Setting Postfix Not Open Relay.

This important part setting postfix. We have to make sure sure that our setting Postfix is not open relay.

Just edit /etc/postfix/main.cf and find mynetworks.

vim /etc/postfix/main.cf

See default mynetworks.

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

Change to:

mynetworks = 127.0.0.0/8, 103.224.124.124/32, 192.168.10.0/24

Where 103.224.124.124/32, 192.168.10.0/24 is IP that allow to using this server to sent email.

That is step by step install postfix Ubuntu 20.04 and tuning deployment in Ubuntu. Please feel free for comment. Maybe usefull.

habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Centos Failed Update Kernel

Today I did a kernel update on my server with Centos 7 OS. At the end of the update process, I found a kernel...
habibzain
1 min read

Easy Fix Missing mirrorlist http://mirrorlist.centos.org on CentOS 7

When running yum update or command that utilize the yum system, errors similar to the following are produced: If you’re encountering issues with the...
habibzain
1 min read

Easy Create Laravel Project with Composer

Requirement Laravel, a popular PHP framework, is renowned for its elegant syntax and robust features, making it a top choice for web developers. One...
habibzain
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss good article from us, get weekly updates in your inbox