Sendmail is an excellent Mail System in Linux. Without any setup, the source address of the sendmail e-mail address is like a userid@localhost.localdo, which is identified as SPAM or rejected by almost all mailboxes.
1. Install Sendmail
In CentOS, sendmail is generally installed with the operating system by default. If the sendmail service is not installed when installing the system, it is easy to manually install sendmail:
view plain copy
# yum install -y sendmail
# yum install -y sendmail-cf
2. Configure SMTP authentication for Senmail (skip this step if authentication is not required)
First, check whether the saslauthd service is installed or started.
Install the saslauthd service: # yum install-y saslauthd
Start saslauthd service: # service saslauthd start
(1) Configure SMTP authentication for Senmail
# Vi/etc/mail/sendmail. mc
view plain copy
dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
Remove the dnl from the above two rows. In the sendmail File, dnl indicates that the behavior comment line is invalid. Therefore, you can enable the corresponding setting line by removing the dnl string at the beginning of the line.
(2) Set network access permissions for the Sendmail service
# Vi/etc/mail/sendmail. mc
view plain copy
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
Change 127.0.0.1 to 0.0.0.0, which means that any host can access the Sendmail service. If only one CIDR block can access the Sendmail service, change 127.0.0.1 to a specific CIDR block address, such as 192.168.1.0/24.
3. Generate the Sendmail configuration file
The configuration file of Sendmail is generated by m4, And the m4 tool is in the sendmail-cf package. If the system cannot identify the m4 command, the sendmail-cf package is not installed.
Generate the configuration file for Sendmail:
view plain copy
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
You must restart Sendmail to make the configuration file take effect.
4. Sendmail mail domain name Configuration
To configure sendmail to use a valid domain name, you can modify the configuration file of sendmail and add the domain name MX record.
Sendmail can directly use the "-r account@domain.com" parameter to send mail at any source address, but the current mainstream mailbox will compare the source address and reverse resolution IP, if the email cannot be parsed or the resolved IP address does not match, the email is directly classified as SPAM. If the email is serious, the email is rejected.
MX Record is mainly used to receive emails. When a new email is delivered, the MX Record of the recipient's domain name is queried and then delivered through the IP address obtained from the MX Record. At the same time, the email manufacturer will compare the source address with the MX record when receiving the mail, as one of the criteria for determining the spam mail.
Step 1: Add a domain name
(1) Add the domain name to the local-host-names File
# Vi/etc/mail/local-host-names, add
view plain copy
sunchis.com
(2) modify the submit. cf file
# Vi/etc/mail/submit. cf, find the line # Dj $ w. Foo. COM, and change it
view plain copy
Djsunchis.com
So far, the sendmail mail naming configuration is complete, and restart sendmail to make the configuration take effect.
Step 2: add the domain name MX record
Find the page for modifying Domain Name Information (different domain name registrar pages are different). The Modification result will take effect within 24 hours at the latest because of different domain name providers.
(1) Add the domain name A record mail and direct it to the static IP address of your email server:
(2) Add (or modify) the MX record of the domain name, such:
(3) Use nslookup to check whether MX records can be correctly resolved to the email server
view plain copy
# nslookup
> set q=mx
> sunchis.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
sunchis.com mail exchanger = 10 mail.sunchis.com.
Authoritative answers can be found from:
>
OK. The email server's domain name has been correctly resolved.
5. Resolution of Relaying denied
550 5.7.1 <xxx@163.com>... relaying denied. IP name lookup failed [192.168.1.20.] is abnormal because sendmail is used as the mail transfer station and the client IP address must be added to the access configuration file.
# Vi/etc/mail/access, add
view plain copy
Connect:192.168.1.133 RELAY
Regenerate the database with access permissions:
view plain copy
# cd /etc/mail/
# makemap hash access.db < access
In this way, the problem will be solved.