Sendmail Mail Server Quick Guide

xiaoxiao2021-03-06  117

I. Overview

Sendmail is the most important email transfer agent. It is very important to understand the working mode of email. Under normal circumstances, we break the email program into user agents, transfer agents and delivery agents. The user agent is used to accept the user's instruction, transfer the user's letters to the letters transmission agent, such as:

Outlook Express, Foxmail, etc. The delivery agent receives the letter from the letters transfer agent to the end user's mailbox, such as: procmail.

When the user tries to send an email, he cannot directly send the letter to the other party, and the user agent must try to find a letter transfer agent and submit mail to it. After the letter transfer agent gets the email, first save it in its own buffer queue, then according to the target address of the message, the Letter Transport Agent will find the mail transfer proxy server that should be responsible for this destination address, and send mail through the network Transfer it. After the other party's server receives the message, buffer it locally until the recipient of the email looks at its own electronic mailbox.

Obviously, mail transfer is from the server to the server, and each user must have a space (called mailbox) that store information on the server (called mailbox) (sending mail is not subject to this limit). It can be seen that the main job of a mail transmission agent is to monitor the user agent request. Find the corresponding mail server according to the target address of the email, transfer the letter between the server and the received mail buffer or submit it to the final delivery program. There are many programs that can be used as a letter transfer agent, but Sendmail is one of these most important, it is true that it can support thousands or even more users, and the occupied system resources are quite small. However, the configuration of Sendmail is very complicated, so some people use additional tools such as qmail, postfix, and more.

When the sendmail program gets a message to be sent, it needs to determine the server to be delivered to the corresponding server based on the target address, which is implemented by the DNS service. For example, an email is the target address of ideal@linuxAid.com.cn, then Sendmail first determines this address is the format of the username (LinuxAid.com.cn), then, by querying DNS to determine needed Letter delivery gives a server.

DNS data, related to email is MX record, such as the following settings in the DNS data file in LinuxAid.com.cn:

IN MX 10 MAIL

IN MX 20 MAIL1

Mail in A 202.99.11.120

Mail1 in A 202.99.11.121

Obviously, in the DNS, LinuxAid.com.cn has two one letters exchange (MX) server, so Sendmail tries to send mail to one of both. In general, the priority of the MX server in front is relatively high, so the server will attempt to connect the 25 port of mail.linuxAid.com.cn, trying to forward the letter message to it. If successful, your SMTP server tasks are completed, in this task, will be completed by mail.linuxaid.com.cn. In general, the MAIL converter will automatically transfer the contents of the letters to the target host, but there is also a case where the target host (such as LinuxAid.com.cn) may not exist, or does not execute SMTP services, but This time, the final letter will be saved on the MX machine until the user will look at it. If the DNS query cannot find MX records for an address (usually because the other party does not have a letter exchange host), Sendmail will be a tried directly to the host of the host, and send an email. For example, there is no corresponding MX record in Test @ aidgroup.linuxAid.com.cndNs, so Sendmail will obtain the other party's IP address from DNS after determining the MX switch failed, and directly and the other party dialogue attempt to send mail.

Second, the work environment

This article assumes that the user wants to set up an email server in the park network environment to provide mail services for the unit users. The server has a legitimate IP address 202.99.11.200 and a legitimate domain name mail.linuxAid.com.cn, and the MX record of DNS also points to this domain name (Note: The sample domain name and IP address are forged domain names and addresses). In order to meet the demand for domain name, DNS domain data files should contain the following:

IN MX 10 MAIL

Mail in A 202.99.11.200

The test environment is: redhat6.2, sendmail.8.11.4, qpopper4.0.3.

three,

software

download

Download sendmail and qpopper from the following address:

Sendmail.8.11.4.tar.gz http://www.sendmail.org/current-release.html

qpopper4.0.3.tar.gz http://www.eudora.com/qpopper_general/

Fourth, Sendmail configuration and installation

Sendmail is currently the most widely used E-mail server. The latest stable version of current is 8.11.4. Download get tar.gz format

After the compression package, store it in the / usr / src directory.

Unzip package:

[root @ email src] # tar xvfz sendmail.8.11.4.tar.gz

[root @ email src] # cd sendmail-8.11.4

Compilation installation:

[root @ email sendmail-8.11.4] # cd sendmail

[root @ email sendmail] # sh bundar

Generate a configuration file:

[root @ email sendmail] #CD /USR/SRC/SENDMAIL-8.11.4/CF/CF/

Generally, there should be a file file file with config.mc, and if you don't create a new file config.mc, the content is:

DIVERT (-1)

DNL this is the macro config file buy to generate the /etc/sendmail.cf

DNL file. if motherate thei file you will have to regenerate trough the m4

DNL Preprocessor:

DNL M4 /etc/sendmail.mc> /etc/sendmail.cf

DNL You Will Need To Have The Sendmail-Cf Package Installed for this to work.

INCLUDE (`/usr/src/sendmail-8.11.4/cf ')

Define (`Confdef_user_id ',` 8: 12')

Ostype (`Linux ')

Undefine (`uucp_relay ')

undefine (`BitNet_Relay ')

Define (`confauto_rebuild ')

Define (`Confto_Connect ',` 1m')

Define (`ConfTry_null_mx_list ', true)

Define (`confdont_probe_interface", true)

Define (`procmail_mailer_path ',` / usr / bin / procmail')

Feature (`SMRSH ',` / usr / sbin / smrsh')

Feature (`Mailertable ',` hash -o / etc / mail / mailertable')

Feature (`Virtusertable ',` hash -o / etc / mail / virtusertable ")

Feature (redirect)

Feature (always_add_domain)

Feature (use_cw_file)

Feature (local_procmail)

MAILER (SMTP)

MAILER (procmail)

Feature (`Access_db ')

Feature (`Blacklist_recip

IENTS ')

DNL WE STRONGLY RECO

Mmend to Comment this one Out if you want to protect

DNL yourself from spam. However, The Laptop and Users on Computers That DO

DNL NOT HAV 24x7 DNS Do NEED THIS.

Feature (`accept_unresolvable_domains')

DNL Feature (`RELAY_BASED_ON_MX ')

Then run:

[root @ email cf] # sh build config.cf

This command will generate config.cf files in this directory. Then install sendmail:

[root @ email sendmail] # sh build install

Copy config.cf to the / etc / mail directory and change the name to sendmail.cf:

[root @ email mail] #CP /usr/src/sendmail-8.11.4/cf/cf/config.cf /etc/mail/sendmail.cf

Create an Access file in the / etc / mail directory, as follows:

127.0.0.1 relay

202.99.11 Relay Here, it means that the machine to pass the machine and 202.99.11.0 network segment through the mail server's forwarding email. Among them, 202.99.11 should be your own

The IP address of the local network IP network segment, only needs to write the network portion. For example, your users have multiple network segments, only need to set multiple network segments in it:

127.0.0.1 relay

202.99.11 relays

200.200.201 Relay

Then generate the Access file to generate easy-to-retrieved library file formats:

[root @ email mail] # Makemap Hash Access.db

Create file / etc / mail / local-host-name, which is the owned domain name information of this unit, because the server has a domain name in the DNS configuration file above: email.linuxAid.com.cn, and MX records Point to this domain, so the server has two domain names, one for email.linuxAid.com.cn and LinuxAid.com.cn so that users can use someone@linuxaid.com.cn. Such addresses send and receive emails, so this The file should include subsequent content:

Linuxaid.com.cn.

Mail.linuxAid.com.cn.

Finally, you have to create an alias database. Create files aliases in / etc / mail / aliases directory, as follows:

Mailer-daemon: postmaster

Postmaster: root

Bin: root

Daemon: root

NoBody: root

Then generate the AliaSS library:

[root @ email mail] # newaliases

Then you can start sendmail:

[root @ email mail] # / usr / sbin / sendmail -bd -q20m

The following error message may appear at the first startup:

554 5.0.0 /etc/mail/sendmail.cf: line 41: UNKNOWN Configuration Line ""

554 5.0.0 /etc/mail/sendmail.cf: line 60: UNKNOWN Configuration Line ""

Don't be nervous, just use the VI editor to delete these rows, in fact, 41, 60, etc. are blank lines. There should be no problem after deleting.

V. Qpopper installation configuration

QPopper is a POP3 server in a UNIX / Linux environment.

Software is used in conjunction with Sendmail. It is mainly to achieve support users receive letters through POP3.

Create a link from / usr / mail to / var / spool / mail / link:

[root @ Email SRC] # ln -s / var / spool / mail / / usr / mail

Unzip QPOPPER software package:

[root @ email src] # tar xvfz qpopper4.0.3.tar.gz

[root @ email src] # cd qpopper4.0.3

Compilation and installation qpopper:

[root @ email qpopper4.0.3] # ./configure

[root @ email qpopper4.0.3] # Make

[root @ email qpopper4.0.3] # Make Install

After the installation is successful, the QPopper will be installed in the directory / usr / local / sbin / directory. Set inetd to boot qpopper. Edit /etc/inetd.conf, find a line of POP content, add ## in front, then add the following: POP-3 Stream TCP NOPPER ot / usr / local / sbin / popper qpopper -s

Then look for the inetd process ID number:

[root @ email qpopper4.0.3] #

PS AX GREP inetd

336? S 0:00 inetd

16872 PTS / 0 S 0:00 GREP inetd

Find the inetd process number 226. Then restart the inetd process and re-read the configuration file:

[root @ www qpopper4.0.3] # kill -hup 336

At this time, check the system service port number:

[root @ email qpopper4.0.3] # netstat -ln grep 110

TCP 0 0 0.0.0.0:110 0.0.0.0:0:0:0:110 0.0.0.0:0:0:110

The 110 port has begun normal service.

6. IMAP server installation test

Realizing the support of IMAP is very simple, just install IMAP

Software package RPM package:

[root @ email rpm] # rpm -ivh IMAP-4.7-5.i386.rpm (here is in the 6.2 environment, if you need to install a higher version of IMAP in the 7.x environment)

Then make sure that the IMAP is located as follows:

IMAP Stream TCP NOWAIT ROOT / USR / SBIN / TCPD IMAPD

Then restart inetd to update the configuration:

[root @ email /] # kill -hup 379 (here 379 is the INETD process number)

Then check if IMAP is successful:

[root @ email /] # NetStat -ln grep 143

Note: IMAP2 is supported for 6.2 version of IMAP-4.7, so it is a 143 port. RH7.x's IMAP-2000 will support IMAP3, so you may also listen to 220 ports)

At this time you can

Add an account in Outlook Express to test.

Seven, test

Next is the email send / receive function of the test mail server. Note: Do not test only the local users, such as: Your domain is abc.com, test, do not only pass Mil, ELM on the mail server The program tests user1@abc.com users. Because the USER1 is the local user, the mail server can perform relay. You should

Another machine on the LAN

The mail clients such as Outlook transceives and receives the server.

This configuration is no problem with IP fixed users, just specify its fixed IP in the Access file, and is not very suitable for applications that need to support mobile users, such as dial-up users, because if the Relay function can cause the mail server A forwarding station called spam.

There are two options to solve user IP unfair issues, one for using SMTP authentication, that is, the user sends a message, the mail server performs user authentication, and the server sends mail, otherwise refuses to send the letter; the second solution is adopted Dynamic Relay Authorization Control, the working principle is: After the dial user dials, first collect mail, if the user can collect the email correctly, the DRAC automatically adds IP that just collects the mail user in Access.db, and Allow this IP to be sent. However, within 30 minutes, this IP does not send / collect mail, DRAC will remove this IP from Access.db. This mechanism ensures that dialing users can send E-mail through the remote mail server without SMTP authentication. These techniques will be discussed in later articles. Eight, FAQ

1, how to set the virtual domain?

Like Apache, Sendmail also allows the use of virtual host features, which is implemented in the MC file, and the virtual host's file default is /etc/mail/virtusrtable.db, which uses / etc / mail / virtusrtable file generation, this file is similar to the AliaSes file, ie the left address right address, the intermediate Tab key is separated. E.g:

Someone@linuxaid.net.cn localuser

Such a line means that the message should be sent to someone@otherdomain.com now to send to the user's Localuser. Of course, this means: first, in your DNS record, this machine should be the MX switch of otherdomain.com; second, your local sendmail.cw file or local-host-names should contain OtherDomain.com first name.

Of course, such a domain is not large, but Sendmail also supports parameters for mail virtual domains. E.g:

@ TestDomain.com Test@linuxaid.com.cn

Means all messages sent to XXX @ TestDomain are sent to TEST@linuxaid.com.cn. and

@ TestDomain.com %1test@linuxaid.com.cn

Then represent parameters escape, such as User1@testDomain.com sent to user1test@linuxaid.com.cn,

User2@testdomain.com is sent to user2test@linuxaid.com.cn. Similarly, such a function is also plugged in by MX records and CW files.

Establishing the method of Virtusertable and establishing Access:

Makemap hash virtusertable.db

Then restart Sendmail.

2, how to set the user alias?

The user's alias is set by file / etc / mail / aliases. The simplest case is the case where letters are required. For example, in general, when an email occurs, we need to send an error-in-mail header to the POSTMASTER user of this machine, but maybe there are multiple system administrators on your system, so everyone needs a copy. Copy of the mail head. In this case, you need to use the user alias file.

The format of the aliases file is the mail alias: the actual username, if a different number of users is separated by a comma, each alias is one line. For example, to send letters sent to Postmaster to Supervisor and Manager, you need to write such a line: Postmaster: Supervisor, Manager

Alias ​​can also be used in such a situation, that is, the automatic mail forwarding is defined. For example, a user has previously accepted email on your system, and now he has a new email, I hope to send it to your machine to automatically forward it to his new email address, then you can use it. Similar to this alias: (assuming your machine is joe@linuxaid.com.cn)

Joe: Joe@xxxxx.com

The email sent to Joe@linuxAid.com will automatically go to Joe@newaddr.com. Note that the left is automatically added to your machine name, so the left side can only be an account name, and it cannot be a fully qualified email address.

Another common way is to redirect. If you define the Redirect feature in the template file, you can use this feature. For example, someone opened an account USER1 on your machine, and then migrated to user2@server2.com. So you can write it alias

User1: user2@server2.com.Redirect

In the future, when someone sent a letter to this address, your sendmail will return it and return a 551 user not local; please try user2@server2.com information.

When using alias, you must pay attention to not cause loop, such as user1 forwarding to user2, and user2 forwards it to user1 .... This cycle. In this case, after forwarding 17 times, Sendmail will refund it to the sender. The most common mistake occurs in the local reserved while trying to forward mail

In the case of backup, for example:

User1: User1, User2

A loop is constituted.

To reserve a backup locally, use the escape symbol, for example

User1: User1, User2

After establishing an alias file, you need to initialize it, which can be done by the newaliase command:

[root @mail mail] # newaliases

/ etc / aliases: 17 Aliases, Longest 31 Bytes, 241 Bytes Total

You can also use the sendmail -bi command:

[root @mail mail] # sendmail -bi

/ etc / aliases: 17 Aliases, Longest 31 Bytes, 241 Bytes Total

The two ways are actually exactly the same.

Similar to mail forwarding through the AliaSes file, users can also use their own forwarding files, for example, a user user1 wants to send it to their own mail to xxxxx@xxxxxx.com, but do not want to establish a global user alias, So, you can build a .forward file below your host directory, and content as long as you are:

XXXXX@xxxxx.com

Yes. This technology allows each user to manage their own mail alias.

转载请注明原文地址:https://www.9cbs.com/read-101521.html

New Post(0)