Three points
1.SMTP Protocol
2. Build local mail server
3. Use external mail server to implement mail function
1.SMTP Protocol
The SMTP (Simple Mail Transfer Protocol) is simply a mail Transfer protocol, a set of rules for sending messages from the source address to the destination to control how the letters are transferred. The SMTP protocol belongs to the TCP/IP protocol cluster, which helps each computer find the next destination when sending or relaying letters. The server specified by the SMTP protocol, you can send e-mail to the recipient's server, the whole process only a few minutes. The SMTP server is the outgoing mail server that follows the SMTP protocol and is used to send or relay outgoing e-mail messages.
SMTP authentication, simply by requiring that you have an account name and password before you can log on to the SMTP server, makes it easy for those spammers to do so. The purpose of increasing SMTP authentication is to protect users from spam.
SMTP listens for connection requests on TCP protocol 25 ports.
In addition, there are two protocols to understand the IMAP protocol, the POP3 protocol
Simply put, the SMTP tube ' hair ', pop3/imap tube ' collect '.
IMAP protocol
The IMAP full name is the Internet Mail Access Protocol, the interactive Mail Access Protocol, which is one of the standard protocols for similar mail access to POP3. On the other hand, when you turn on IMAP, the messages you receive from the email client remain on the server, and the actions on the client are fed back to the server, such as deleting the message, marking the read, and so on, and the message on the server will act accordingly. So whether you log in to the mailbox from the browser or the client software login mailbox, see the message and the status is consistent.
The main difference between it and the POP3 protocol is that the user can not download all the mail, can be directly through the client to the server to operate the message
POP3 Protocol
POP3 is the post Office Protocol 3 abbreviation, the 3rd version of the Post Office Protocol, which provides a way to connect personal computers to the Internet's mail server and electronic protocols for downloading e-mail. It is the first offline protocol standard for Internet e-mail, POP3 allows users to store messages from a server on a local host (that is, their own computer) while deleting messages that are saved on the mail server, and the POP3 server follows the POP3 protocol's receiving mail server to receive e-mail. Instance:
NetEase Yeah mailbox related server information:
Mail server name |
Server Address |
Port number |
POP3 Server |
pop.yeah.net |
the |
SMTP Server |
smtp.yeah.net |
- |
IMAP Server |
imap.yeah.net |
143
|
Use Telnet to demonstrate the SMTP interaction process $telnet smtp.163. COM 25 Send Connection
163.com Anti-Spam GT for Coremail System (163com[20141201]) Response 220 service Ready Helo 66 HELO command Mark own identity OK Response 250 request mail action correct, complete
Auth Login Login Authentication 334 DXNLCM5HBWU6 Required input Username:
Here, enter USERbase64 encrypted username
334 UGFZC3DVCMQ6 requires input password: Here, enter PASSbase64 encrypted password.
235 Authentication Successful Response 235: certification passed
mailfrom:xxx@163. COM represents the sender's e-mail address
Mail OK
rcptto:xxx@163. COM identifies the recipient's e-mail address
Mail OK
DATA
Data for 354 end data with messages . with a "." The beginning of the row as the end of the data part identification
2. Build local mail server
First, there are three concepts.
Internet Mail system is through a few complex partial connection, for end users, we are familiar with the Outlook,foxmai,linux mail, MAILX, nail, etc. are used to receive letters and letters, called Mua:mail User agent, mail user agents
MUA not send mail directly to the recipient, but through the mta:mail Transfer agent, the message transfer Agent on behalf of the transfer, SendMail and Postfix is playing the role of MTA.
After a message is issued from the MUA, it may pass through one or more MTA, and eventually arrives at the mda:mail Delivery agent, the mail delivery Agent , and the message arrives in the MDA and is stored in a file or special database. We call this a mailbox for a long time to keep the mail.
Combined with the contents of the first part, a letter is sent from MUA to the MTA, and the protocol used between the MTA and the MTA is the SMTP protocol , and the protocol used by MUA to the MDA is most commonly used for POP3 or IMAPwhen the message is received.
Sender: MUA--Send--> MTA-> several MTAs ...-> MTA-> MDA <--Receive--MUA: Recipient
So we set up a local mail server to provide the message transfer agent and mail delivery Agent two services
The current comparison of the mainstream is SendMail + Dovecot to provide these two services
However, the configuration of SendMail is very complex, so some other tools, such as qmail, Postfix and so on, are also used. For example, use Postfix + dovecot
This is mainly about the next SendMail + Dovecot,
2.1 Configure domain names and networks
Public network IP 1.1.1.1 Domain name for yunwei521.top Add this resolution at the DNS service provider
Host record @ record type MX record value 1.1.1.1 This allows you to provide mailbox services such as Xxx@yunwei521.top.
If you just want to do a test in the intranet, first create a DNS server (192.168.1.1) and add resolution to resolve the domain name to 192.168.1.2 the mail server we want to create.
2.2 installation software
Install mail server
# yum Install SendMail SENDMAIL-CF
Install Pop3/imap Service
# yum Install Dovecot
Install user authentication
# yum Install CYRUS-SASL
# yum Install Cyrus-sasl-md5
# yum Install Cyrus-sasl-plain
# yum Install Cyrus-sasl-lib
Turn on the firewall (SMTP), 143 (IMAP) port, and close the SELinux
2.3 Software Configuration
Configure SendMail to enter/etc/mail
# Cd/etc/mail
3.1 Configuring Access
# vi/etc/mail/access
In general, SendMail does not relay information for mail services, which prevents malicious people from using other people's mail servers to send hair messages, so access keeps the default configuration
The contents are as follows
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
connect:127.0.0.1 RELAY
Of course, can also be for a certain section of IP or an IP to make changes, such as to prohibit an IP letter, you can add
192.168.0.2 deny
Run the following command to compile after saving the file
# Makemap Hash Access.db < access
3.2 Configuring TLS (support for encrypted connections LLS)
First generate Sendmail.pem file
# Cd/etc/pki/tls/certs
# Make Sendmail.pem
Country Name (2 letter code) [Gb]:ch
State or province Name (full name) [Berkshire]:sh
Locality Name (eg, city) [Newbury]:sh
Organization Name (eg, company) [Me company ltd]:test.
Organizational unit Name (eg, section) []:it
Common name (eg, your name or your server ' s hostname) []: server110. com
e-mail address []:test@ server110. com
3.3 Configuration Sendmail.mc
# VI/ETC/MAIL/SENDMAIL.MC
Add to:
Define (' confauth_options ', ' A P y ') dnl
Define (' Confcacert_path ', '/etc/pki/tls/certs ') dnl
Define (' Confcacert ', '/etc/pki/tls/certs/ca-bundle.crt ') dnl
Define (' Confserver_cert ', '/etc/pki/tls/certs/sendmail.pem ') dnl
Define (' Confserver_key ', '/etc/pki/tls/certs/sendmail.pem ') dnl
If so, the default is DNL annotation, and the previous dnl annotation can be deleted
Uncomment the following two lines (delete the DNL at the beginning)
Trust_auth_mech (' EXTERNAL digest-md5 cram-md5 LOGIN PLAIN ') dnl
Define (' confauth_mechanisms ', ' EXTERNAL GSSAPI digest-md5 cram-md5 LOGIN PLAIN ') dnl
Modify the listening IP for SMTP to 0.0.0.0
Daemon_options (' port=smtp,addr=0.0.0.0, Name=mta ') dnl
Don't change