Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Postfix mail server for Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Linux how to configure Postfix mail server related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this Linux how to configure Postfix mail server article, let's take a look.

Step 1) the first step in updating the system is to ensure that the system package is up to date. To do this, update the system as follows:

Before # dnf update continues, make sure that no other MTA (such as Sendmail) exists, as this will result in a conflict with the Postfix configuration. For example, to delete a Sendmail, run the following command:

# dnf remove sendmail step 2) set the hostname and update / etc/hosts use the following hostnamectl command to set the hostname on the system:

# hostnamectl set-hostname server1.crazytechgeek.info# exec bash in addition, you need to add the hostname and IP of the system to / etc/hosts:

# vim / etc/hosts192.168.1.13 server1.crazytechgeek.info save and exit the file.

Step 3) install Postfix mail server to verify that there is no other MTA running on the system, run the following command to install Postfix:

# dnf install postfix

Install-Postfix-Centos8

Step 4) after starting and enabling the Postfix service, after successfully installing Postfix, run the following command to start and enable the Postfix service:

# systemctl start postfix# systemctl enable postfix to check the Postfix status, run the following systemctl command:

# systemctl status postfix

Start-Postfix-check-status-centos8

Great, we have verified that Postfix is up and running. Next, we will configure Postfix to send mail locally to our server.

Step 5) install mailx Mail client before configuring the Postfix server, we need to install mailx. To install it, run the following command:

# dnf install mailx

Install-Mailx-CentOS8

Step 6) the configuration file for configuring the Postfix mail server Postfix is located in / etc/postfix/main.cf. We need to make some changes to the configuration file, so please open it using your favorite text editor:

# vi / etc/postfix/main.cf change the following lines:

Myhostname = server1.crazytechgeek.infomydomain = crazytechgeek.infomyorigin = $mydomain## uncomment and set inet_interfaces to all##inet_interfaces = all## to change to all##inet_ protocols = all## comment # mydestination = $myhostname, localhost.$mydomain, localhost## uncomment # # mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain## uncomment and add IP range # # mynetworks = 192.168.1.0 127.0.0.0Universe # Uncomment # # home_mailbox = Maildir/ after completion Save and exit the configuration file. Restart the postfix service for the changes to take effect:

# systemctl restart postfix step 7) Test the Postfix mail server to test whether our configuration is valid. First, create a test user.

# useradd postfixuser# passwd postfixuser next, run the following command to send mail from the local user pkumar to another user postfixuser.

# telnet localhost smtp or # telnet localhost 25 if the telnet service is not installed, you can install it using the following command:

# dnf install telnet-y when you run the command as mentioned earlier, you should get the following output:

The result above [root@linuxtechi ~] # telnet localhost 25Trying 127.0.0.1...Connected to localhost.Escape character is'^] '.220 server1.crazytechgeek.info ESMTP Postfix confirms that the connection to the postfix mail server is normal. Next, enter the command:

The # ehlo localhost output looks like this:

250-server1.crazytechgeek.info250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 SMTPUTF8 next, run the orange highlighted commands, such as mail from, rcpt to, data, and finally type quit:

Mail from:250 2.1.0 Okrcpt to:250 2.1.5 Okdata354 End data with.Hello, Welcome to my mailserver (Postfix) .250 2.0.0 Ok: queued as B56BF1189BECquit221 2.0.0 ByeConnection closed by foreign host completes the telnet command to send mail from the local user pkumar to another local user postfixuser, as follows:

Send-email-with-telnet-centos8

If everything goes according to plan, you should be able to view the emails sent in the new user's home directory:

# ls / home/postfixuser/Maildir/new1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info# to read the email, simply use the cat command, as follows:

# cat / home/postfixuser/Maildir/new/1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info

Read-postfix-email-linux

Postfix mail server log Postfix mail server mail log is saved in the file / var/log/maillog, use the following command to view the real-time log

# tail-f / var/log/maillog

Postfix-maillogs-centos8

Protecting the Postfix mail server recommends that you always secure communication between the client and the Postfix server, which can be achieved using SSL certificates, which can come from trusted authorities or self-signed certificates. In this tutorial, we will use the openssl command to generate a self-signed certificate for Postfix

I assume that openssl is already installed on your system. If not, use the following dnf command:

# dnf install openssl-y uses the following openssl command to generate the private key and CSR (certificate signing request):

# openssl req-nodes-newkey rsa:2048-keyout mail.key-out mail.csr

Postfix-Key-CSR-CentOS8

Now, use the following openssl command to generate a self-signed certificate:

# openssl x509-req-days 365-in mail.csr-signkey mail.key-out mail.crtSignature oksubject=C = IN, ST = New Delhi, L = New Delhi, O = IT, OU = IT, CN = server1.crazytechgeek.info, emailAddress = root@linuxtechiGetting Private key# now copy the private key and certificate file to the / etc/postfix directory:

# cp mail.key mail.crt / etc/postfix updates the path of the private key and certificate file in the Postfix configuration file:

# vi / etc/postfix/main.cf. Smtpd_use_tls = yessmtpd_tls_cert_file = / etc/postfix/mail.crtsmtpd_tls_key_file = / etc/postfix/mail.keysmtpd_tls_security_level = may. Restart the Postfix service for the above changes to take effect:

# systemctl restart postfix lets us try to use the mailx client to send messages to internal local and external domains.

Send internal local mail from pkumar to postfixuser:

# echo "test email" | mailx-s "Test email from Postfix MailServer"-r root@linuxtechi root@linuxtechi uses the following command to check and read the email:

# cd / home/postfixuser/Maildir/new/# lltotal 8 RWMI. 1 postfixuser postfixuser 476 Nov 12 17:34 1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.infomurrwmuri. 1 postfixuser postfixuser 612 Nov 13 02:40 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info# cat 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info

Read-Postfixuser-Email-CentOS8

Send mail from postfixuser to external domain (root@linuxtechi.com):

# echo "External Test email" | mailx-s "Postfix MailServer"-r root@linuxtechi root@linuxtechi Note: if your IP is not blacklisted anywhere, the email you send to the external domain will be sent, otherwise it will be returned and your IP will be blacklisted by a database such as spamhaus.

Check the Postfix message queue to list the messages in the queue using the mailq command:

# mailqMail queue is empty#, this is the end of the article on "how to configure Postfix mail server with Linux". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to configure Postfix mail server in Linux". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report