Configure Postfix in Centos to replace Sendmail with the sending server

Source: Internet
Author: User
Tags tld mx record
The MX record may take effect for a period of time (usually several minutes or tens of minutes, or immediately) after it is added. Therefore, before you install the configuration, first, we add the domain name. because the MX record may take effect for a period of time (usually several minutes or tens of minutes, it may take effect immediately), before you install the configuration, first, add an MX record for the domain name. The method for adding a domain name may vary with the domain name ISP, but the general information is as follows (for example, DNSPOD ):



DNSPOD settings
How to check whether adding an MX record takes effect:
# Host-t mx naic. ccnaic. cc mail is handled by 15 123.123.123.123 (Your IP address ).

Then install Postfix
Because CentOS is used, all the direct yum commands can be installed.
# yum -y install postfix


Configure Postfix and related components
Configure Postfix
# Vi/etc/postfix/main. cf # myhostname = host. domain. tld marker finds this line and changes the part after the equal sign to the host name using myhostname = mail. naic. cc flood changes 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 registrant mydomain = naic. cc flood changes to this status. set the domain name (we will set it here as part of the email address "@") # myorigin = $ mydomain locate to find this line, change the # at the beginning of the line to the desired myorigin = $ mydomain succeeded state. set the part after the Mail address "@" to the domain name (non-system host name) inet_interfaces = localhost succeeded to find this line, change "localhost" to "all" ↓ inet_interfaces = all hosts to this status, and accept requests from all networks (you do not need to change them only in this instance) # local_recipient_maps = hosts find this line, remove the previous # export local_recipient_maps = export to this status, and allow emails to be sent to any address # relay_domains = $ mydestination locate this line, remove repeated relay_domains = $ mydestination domains from the beginning of the line and change them to this status. define the domain name that allows forwarding # mynetworks = 168.100.189.0/28,127.0 .0.0/8 bytes to find this line, modify your mynetworks = 123.123.123.123 region to this status based on your intranet. specify the intranet and local IP address ranges (because I only have public IP addresses) # home_mailbox = Maildir/region to find this line, remove the # mailbox home_mailbox = Maildir/mailbox at the beginning of the line and change it to this state. specify the user email directory # smtpd_banner = $ myhostname ESMTP $ mail_name ($ mail_version) and locate this line, add the following line to this line: smtpd_banner = $ myhostname ESMTP unknow rows add this line. The SMTP server information is not displayed at the end of the configuration file. add the following line: authorization = yes authentication the server uses SMTP Authentication smtpd_sasl_local_domain = $ myhostname authentication to specify the local domain name for SMTP Authentication (host name) authorization = noanonymous authentication does not allow anonymous Authentication Authorization = permit_mynetworks, permit_sasl_authenticated, limit = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination limit (very important) message_size_limit = 15728640 limit indicates that the maximum email size is 15 MB.


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.
# Vi/usr/lib/sasl2/smtpd. confpwcheck_method: saslauthd locate this row and change "saslauthd" to "auxprop" into pwcheck_method: auxprop login does not use the system user password as the user's SMTP authentication password # vi/etc/sysconfig/saslauthdMECH = pam login find this line, add # Authorization # MECH = pam authentication in front of the table. do not use the pam mechanism FLAGS = authorization to find this row. add "sasldb" character FLAGS = sasldb signature after the equal sign to define the authentication method as sasldb2.

Create a user's email directory (this step can be omitted when sending SMTP messages separately)
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

Then create a mailbox Directory for the user.
# Mkdir/home/mail/Maildir users: (here, the mail user is used as an example) create the email directory # chmod 700/home/mail/Maildir folder and set the user's email directory attribute to 700 # chown mail. /home/mail/Maildir folder set the user's email directory to all

Set SMTP authentication password for users
Set the SMTP authentication password for the naic user (the user name and password here are the user name and password for SMTP authentication)
# Saslpasswd2-u mail. naic. cc-c naicPassword: login enter the password here (not displayed like logon) Again (for verification): login enter the password Again

Changing attributes and attributes of SALS
# Change the database ownership to postfix in chgrp postfix/etc/sasldb2 connector. # Change the database attribute to 640 in chmod 640/etc/sasldb2 connector.

KO drop sendmail service and set postfix to default MTA
Because Postfix is used as the SMTP server, we don't want to use sendmail any more, so we don't need to stop using sendmail.
#/Etc/rc. d/init. d/sendmail stopShutting down sendmail: [OK] Shutting down sm-client: [OK] # chkconfig sendmail off manual disable sendmail self-start # chkconfig -- list sendmail restart confirm that sendmail self-start has been disabled (all are off OK) 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 parameters set the default MTAThere are 2 programs which provide 'mta '. selection Command -------------- * + 1/usr/sbin/sendmail. sendmail enabled Current status: sendmail is the default MTA2/usr/sbin/sendmail. postfixEnter 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 restart confirm SMTP-Auth service status saslauthd 0: off 1: off 2: on 3: on 4: on 5: on 6: off confirm 2 ~ 5. if the status is on, OK #/etc/rc. d/init. d/saslauthd start restart start SMTP-AuthStarting saslauthd: [OK] # chkconfig postfix on startup set Postfix to self-start # chkconfig -- list postfix fix success confirm Postfix service status postfix 0: off 1: off 2: on 3: on 4: on 5: on 6: off confirm 2 ~ 5. if the status is on, run OK #/etc/rc. d/init. d/postfix start restart to start PostfixStarting postfix: [OK].

Okay. use the username and password you just set to try sending emails ~
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.