1. Install Postfix online
Yum-y install Postfix
2. Edit the Postfix configuration file
VI/etc/Postfix/Main. cf
# Myhostname = host. domain. TLD locate this line and rewrite the part after the equal sign to the Host Name
Bytes
Myhostname = sample.centospub.com changed to this status. Set the Host Name of the system.
# Mydomain = domain. TLD locate this line and rewrite the part after the equal sign to the domain name
Bytes
Mydomain = centospub.com is changed to this status. Set the domain name (we will set this as part of the email address)
# Myorigin = $ mydomain names find this row and remove the first line #
Bytes
Myorigin = $ mydomain names changed to this status. Set the part after the mail address "@" to a domain name (non-system host name)
Inet_interfaces = localhost found this line and changed "localhost" to "all"
Bytes
Inet_interfaces = all requests are changed to this status, and requests from all networks are accepted.
Mydestination = $ myhostname, localhost. $ mydomain, localhost locate this row and add "$ mydomain" to the behavior"
Bytes
Mydestination = $ myhostname, localhost. $ mydomain, localhost, $ mydomain changed to this status, specifying the domain name sent to the local email
# Relay_domains = $ mydestination locate this row and remove the first line #
Bytes
Relay_domains = $ mydestination domains changed to this status, defining the domain names allowed for forwarding
# Mynetworks = 168.100.189.0/28,127.0 .0.0/8 locate this line and modify it according to your intranet Conditions
Bytes
Mynetworks = 168.100.189.0/28,127.0 .0.0/8 then changes to this status, specifying the Intranet and local IP address ranges
# Home_mailbox = maildir/empty find this line and remove the line at the beginning #
Bytes
Home_mailbox = maildir/inbox changed to this status, specifying the user email directory
# Smtpd_banner = $ myhostname ESMTP $ mail_name ($ mail_version) locate this line and add the following line to this line:
Smtpd_banner = $ myhostname ESMTP unknow rows add this line, no information about the SMTP server is displayed
Add the following lines at the end of the configuration file:
Smtpd_sasl_auth_enable = yes. The slave server uses SMTP authentication.
Smtpd_sasl_local_domain = $ myhostname authentication specifies the local domain name (host name) for SMTP authentication)
Smtpd_sasl_security_options = noanonymous Anonymous Authentication Not Allowed
Smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
Message_size_limit = 15728640 limit the maximum size of the email is 15 MB.
3. Configure SMTP authentication options
To improve security, we will not use the password of the System user as the password for SMTP authentication for the corresponding user, but will create a dedicated password for SMTP authentication for the user later.
For a 64-bit system, modify lib64
Edit SMTP authentication configuration file
VI/usr/lib64/sasl2/smtpd. conf
VI/usr/lib64/SASL/smtpd. conf
VI/usr/lib/sasl2/smtpd. conf
Pwcheck_method: saslauthd locate this line and change "saslauthd" to "auxprop"
Bytes
Pwcheck_method: auxprop keystore does not use the System user password as the user's SMTP authentication Password
[Root @ sample ~] # Vi/etc/sysconfig/saslauthd
Mech = shadow cursor find this line and add #
Bytes
# Mech = shadow watermark does not use the shadow Mechanism
Flags = login find this line and add "sasldb" after the equal sign"
Bytes
Flags = sasldb connector defines the authentication method as sasldb2
[3] creating a user's email directory
First, create a mailbox directory under the user template, so that when you create a new user, the corresponding user's mailbox directory is automatically created.
Mkdir/etc/skel/maildir Folder: create a user email directory under the user Template
Chmod 700/etc/skel/maildir folder set the user email directory attribute to 700
Create a mailbox directory for an existing user.
Mkdir/home/centospub/maildir folder is used as the user (here, the centospub user is used as an example) to create a mailbox directory.
Chmod 700/home/centospub/maildir folder set the user's email directory attribute to 700
Chown centospub./home/centospub/maildir folder
[4] setting SMTP authentication password for users
Saslpasswd2-u sample.centospub.com-C centospub encrypt sets the SMTP authentication password for the centospub user
Password: Login enter the password here (not displayed)
Again (for verification): enter your password again
[5] changing attributes and attributes of SALS
Chgrp Postfix/etc/sasldb2 connector changes the database ownership to Postfix,
Chmod 640/etc/sasldb2 connector changed the database attribute to 640
[6] disable the sendmail service and set the default MTA
Because we do not need to use sendmail when using Postfix as the SMTP server, we need to disable the sendmail service to ensure security and save system resources.
/Etc/rc. d/init. d/sendmail stop quit Disable sendmail service
You can uninstall Yum remove Sendmail directly if you do not need it.
Shutting down Sendmail: [OK]
Shutting down Sm-Client: [OK]
Chkconfig Sendmail off Manual Disable sendmail auto-start
Chkconfig -- list | grep Sendmail enabled: Make sure that Sendmail is disabled since it was started (it is OK if it is all off)
Sendmail 0: off 1: off 2: off 3: off 4: off 5: off 6: Off
Then, set the default MTA to postfix.
Alternatives -- config MTA instances set the default MTA
There are 2 programs which provide 'mta '.
Selection command
-----------------------------------------------
* + 1/usr/sbin/sendmail. Sendmail enabled Current status: Sendmail is the default MTA
2/usr/sbin/sendmail. Postfix
Enter to keep the current selection [+], or type selection number: 2 rows enter 2 here to make Postfix the default MTA
Start the corresponding service
Finally, start the SMTP authentication and Postfix services, and set the corresponding services to self-start.
Chkconfig saslauthd on login set SMTP-auth to self-start
Chkconfig -- list saslauthd validation to confirm the SMTP-auth service status
Saslauthd 0: off 1: off 2: On 3: On 4: On 5: on 6: off done OK 2 ~ 5. If the status is on, OK.
/Etc/rc. d/init. d/saslauthd start restart start SMTP-auth
Starting saslauthd: [OK]
Chkconfig Postfix on startup
Chkconfig -- list Postfix consumer confirm the Postfix service status
Postfix 0: off 1: off 2: On 3: On 4: On 5: on 6: off done OK 2 ~ 5. If the status is on, OK.
/Etc/rc. d/init. d/Postfix start marker start Postfix
Starting Postfix: [OK]
So far, the SMTP server configuration has been completed, but currently only the function of sending emails from the backup client through the server is available. As a complete mail server, you also need to use the POP/IMAP protocol to receive emails from the client to the local device.
Test transmission:
Telnet 192.168.1.10 25
Trying 192.168.33.10...
Connected to yunwei2.uid5a.cn (192.168.33.10 ).
Escape Character is '^]'.
220 yunwei2.uid5a.cn ESMTP unknow
Mail from: xiaoqi@uid2.com
250 2.1.0 OK
Rcpt to: 142132456@qq.com
250 2.1.5 OK
Data
354 end data with <CR> <LF>. <CR> <LF>
Subject: ajdslflkasdf
Asadlfkadsklfads
Dsaflkjadsflkadsfad
Sadssdlfkasd
.
250 2.0.0 OK: queued as 56b29c2823e
For the construction of POP/IMAP servers, see section 2_pop/IMAP Server construction (Dovecot) in the next section)
Reference: http://www.centospub.com/make/postfix_smtp.html