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 use forwarding server to handle mail communication on Linux system

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "how to use the forwarding server to deal with mail communication on the Linux system". In the daily operation, I believe that many people have doubts about how to use the forwarding server to deal with the mail communication problem on the Linux system. The editor has consulted all kinds of materials and sorted out the simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to use the forwarding server to deal with mail communication on the Linux system". Next, please follow the editor to study!

When you start and run the application server, you need a good mail server to deliver mail for you. I have activated postfix mail service for all my servers. Here are my common configurations.

Install Postfix on CentOS 6

The code is as follows:

Yum install postfix

Sendmail is installed by default, so it's best to stop it and remove it.

The code is as follows:

Service sendmail stop

Yum remove sendmail

Postfix contains two configuration files, main.cf and master.cf. For the basic configuration, you need to modify main.cf. At the same time, postfix can define parameters like shell variables and call them with $. These parameters no longer need to be defined before, and Postfix queries a parameter only when it is needed at run time.

Configure postfix

The code is as follows:

Vim / etc/postfix/main.cf

Remove comments from the following lines

The code is as follows:

# your hostname

Myhostname = yourhostname.com

# your sending domain

Myorigin = $myhostname

# specify the network interface used to receive mail. Localhost is specified here because we only use it to accept local program delivery.

Inet_interfaces = localhost

# specify the protocol to be used. You can use "all" to add IPv6 support

Inet_protocols = ipv4

# specify the accepted mail domain

Mydestination = $myhostname, localhost.$mydomain, localhost

# only forward messages from the local host, not the network on which the host is located

Mynetworks_style = host

Start postfix

The code is as follows:

Service postfix start

These basic postfix configurations allow your machine to send email, which you can verify by sending email and checking the "maillog" log file.

The code is as follows:

Echo test mail | mail-s "test" leo@techarena51.com & & sudo tail-f / var/log/maillog

# the output log is similar to the following

Aug 25 14:16:21 vps postfix/smtp [32622]: E6A372DC065D: to=, relay=smtp.mailserver.org [50.56.21.176], delay=0.8, delays=0.1/0/0.43/0.27, dsn=2.0.0, status=sent (250 Great success)

Aug 25 14:16:21 vps postfix/qmgr [5355]: E6A372DC065D: removed

However, the above configuration is not enough, because the mail service is full of spam most of the time, and you need to add SPF, PTR and DKIM records. Even so, your email may still be sent as spam because your IP address is blacklisted, mostly because your vps has been previously hacked.

There is another option, or even better, to use mail services provided by third-party mail providers, such as Gmail, or even Mailgun. I use Mailgun because they provide 10000 free emails a month, while Gmail provides about 100 emails a day.

In "/ etc/postfix/main.cf", you need to add "smtp.mailgun.com" as your "forwarding host" and enable "SASL" authentication so that postfix can connect and authenticate to the remote Mailgun server.

Add or uncomment the following lines.

The code is as follows:

Relayhost = [smtp.mailgun.org]

Smtp_sasl_auth_enable = yes

Smtp_sasl_password_maps=static:your_username:your_password

Smtp_sasl_security_options=noanonymous

Postfix itself does not implement "SASL" authentication, so you need to install "cyrus-sasl-plain".

The code is as follows:

Sudo yum install cyrus-sasl-plain

If you do not install this package, you will receive the error message "SASL authentication failed; cannot authenticate to server smtp.mailgun.org [50.56.21.176]: no mechanism available)"

Restart postfix

The code is as follows:

Sudo service postfix restart

Using TLS to strengthen Postfix Security

Postfix supports TLS, which is the successor to SSL and allows you to encrypt data using key-based authentication. I recommend that you read http://www.postfix.org/TLS_README.html to see how TLS works with postfix.

To use TLS, you need to generate a private key and a certificate issued by a certificate authority. In this case, I will use the self-issued certificate.

The code is as follows:

Sudo yum install mod_ssl openssl

# generate private key

Openssl genrsa-out smtp.key 2048

# generate CSR

Openssl req-new-key smtp.key-out smtp.csr

# generate self-signed keys

Openssl x509-req-days 365-in smtp.csr-signkey smtp.key-out smtp.crt

# copy the file to the correct location

Cp smtp.crt / etc/pki/tls/certs

Cp smtp.key / etc/pki/tls/private/smtp.key

Cp smtp.csr / etc/pki/tls/private/smtp.csr

Open the postfix configuration file and add the following parameters.

The code is as follows:

Sudo vim / etc/postfix/main.cf

Smtp_tls_security_level = may

Smtpd_tls_security_level = may

Smtp_tls_note_starttls_offer = yes

Smtpd_tls_key_file = / etc/pki/tls/private/smtp.key

Smtpd_tls_cert_file = / etc/pki/tls/certs

Smtp_tls_CAfile = / etc/ssl/certs/ca.crt

Smtp_tls_loglevel = 1

The security level "may" means declaring support for STARTTLS on a remote SMTP client, but the client does not need to use encryption. I use "may" here as prompted by the mailgun documentation, but if you want to force TLS encryption, you can use "encrypt".

The code is as follows:

Service postfix restart

# send a test email

Echo test mail | mail-s "test" test@yourdomain.com & & sudo tail-f / var/log/maillog

You should see the following message

The code is as follows:

Aug 21 00:00:06 vps postfix/smtp [4997]: setting up TLS connection to smtp.mailgun.org [50.56.21.176]: 587

Aug 21 00:00:06 vps postfix/smtp [4997]: Trusted TLS connection established to smtp.mailgun.org [50.56.21.176]: 587: TLSv1.2 with cipher AES256-GCM-SHA384 (256 bits)

If everything is all right, you can comment out the following parameters.

The code is as follows:

"smtp_tls_loglevel = 1"

At this point, the study on "how to use the forwarding server to handle e-mail communication on the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Servers

Wechat

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

12
Report