Jump to content

Debian 12: Konfigurasi Postfix

From Wiki
Revision as of 21:06, 5 February 2025 by Kangtain (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Configure Mail Server Hostname

I assume you have a sudo user on your Debian server. Run the following commands on the server as root to install sudo.

apt install sudo

Log into your server via SSH and enter the following command to see the FQDN form of your server hostname.

hostname -f

If your Debian server doesn’t have an FQDN yet, you can use hostnamectl to set one.

sudo hostnamectl set-hostname your-fqdn

Install Postfix SMTP Server on Debian Server

On your Debian server, run the following two commands.

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

You will be asked to select a type for mail configuration. Normally, you will want to select the second type: Internet Site.

  • No configuration means the installation process will not configure any parameters in the /etc/postfix/main.cf file.
  • Internet Site means using Postfix for sending emails to other MTAs and receiving emails from other MTAs.
  • Internet with smarthost means using postfix to receive email from other MTAs, but using another smart host to relay emails to the recipient.
  • Satellite system means using a smart host for sending and receiving emails.
  • Local only means emails are transmitted between local user accounts only.

How To Increase Attachment Size Limit

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

sudo 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.

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

sudo postconf -e message_size_limit=52428800

When postconf command is invoked with the -e (edit) option, it will try to find the parameter (message_size_limit) in the Postfix main configuration file (/etc/postfix/main.cf) and change the value. If the parameter can’t be found, then it adds the parameter at the end of the file.

Note that the message_size_limit should not be larger than the mailbox_size_limit, otherwise Postfix might not be able to receive emails. The default value of mailbox_size_limit is 51200000 bytes (about 48MB) in the upstream Postfix package. On Debian, the default value is set to 0, as can be seen with

sudo postconf | grep mailbox_size_limit

Output:

mailbox_size_limit = 0

This means that the mailbox has no size limit, which is great.

Restart Postfix for the changes to take effect.

sudo systemctl restart postfix

When sending an email with large attachments from your mail server, you should also beware of the receiving server’s attachment size limit. For example, You can not send an attachment larger than 25MB to a Gmail address.

Setting the Postfix Hostname

By default, Postfix SMTP server uses the OS’s hostname. However, the OS hostname might change, so it’s a good practice to set the hostname directly in Postfix configuration file. Open the Postfix main configuration file with a command-line text editor, such as Nano.

sudo nano /etc/postfix/main.cf

Find the myhostname parameter and set mail.example.com as the value. It’s not recommended to use the apex domain example.com as myhostname. Technically you can use the apex domain, but it will create problems in later parts of this tutorial series.

myhostname = mail.example.com

Save and close the file. (To save a file in Nano text editor, press Ctrl+O, then press Enter to confirm. To exit, press Ctrl+X.) Restart Postfix for the change to take effect.

sudo systemctl restart postfix

Once you have set myhostname in Postfix, the OS hostname doesn’t matter anymore. You can change the OS hostname to any hostname you like.

Using IPv4 Only

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

sudo 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

Source