The principle of mail sending and receiving and the deployment of postfix mail system

Table of contents

1. The principle of sending and receiving emails

1. Schematic diagram and explanation of terms

2. MTA function introduction

3. POP and IMAP get email introduction

2. Deploy postfix mail system

1. Environment preparation

2. DNS server deployment

3. Deploy Postfix

4. Deploy Dovecot

3. Use Foxmail to test

1. Modify the DNS server

2. Foxmail login test account

3. Send a test email 

4. The server checks the mail


1. The principle of sending and receiving emails

1. Schematic diagram and explanation of terms

MUA (Mail User Agent): mail user agent, such as common Foxmail, NetEase client, etc.

MTA (Mail Transfer Agent): Internet mail transfer agent, a program that forwards letters from MUA to designated users.

MX (Mail Exchanger): The mail exchange record in DNS points to a mail server.

POP (Post Office Protocol): Post Office Protocol, that is, the user downloads the mail from the SMTP storage to the local.

IMAP (Internet Mail Access Protocol): Mail access protocol, users can view mail and other information online in SMTP storage.

sent/receive: Indicates the sending and receiving users

2. MTA function introduction

①Mail transmission: MTA mail server is responsible for receiving, transmitting and delivering emails.

②Mail routing: MTA mail server delivers emails from the sender to the receiver by setting mail transmission rules and routing policies.

③Mail queuing and retrying: MTA mail server will put emails into the queue for queuing, so that when problems are encountered during the transmission process, retry delivery.

④Mail security: MTA mail server can apply various mail security mechanisms, such as encryption, verification and anti-spam (SPAM) filtering. It can use encryption protocols (such as TLS/SSL) to protect the transmission security of emails.

⑤ Mail management and monitoring: MTA mail server provides management and monitoring functions, enabling administrators to monitor mail transmission status, adjust server configuration and policies, manage user accounts and mail storage, etc. Administrators can track the process of mail delivery, check error logs and troubleshoot to ensure the normal operation of the mail system.

3. POP and IMAP get email introduction

①Mail storage location: When using POP, the mail is usually downloaded from the mail server to the local and deleted on the server, while when using IMAP, the mail is kept on the server and the local device only keeps a copy of the mail.

②Mail synchronization: Since POP downloads mail to the local, the device will not synchronize the status (read/unread) when viewing it. IMAP can keep synchronizing with the server, and the status will be synchronized no matter which device is viewing the mail.

③Mail use: POP can be downloaded to the local to view the mail without the network, and IMAP requires a network connection to access the mail on the server.

④Email management: POP has relatively few functions to manage emails, and IMAP can create and delete mobile folders on the server to manage emails.

2. Deploy postfix mail system

1. Environment preparation

CPU name operating system IP address installer effect
mail-server centos7.6 192.168.30.20 named、postfix、dovecot DNS server and mail server
windows10 windows10 192.168.30.200 Foxmail client Test mail function

2. DNS server deployment

mail-server执行:
hostnamectl set-hostname mail-server
#修改主机名
systemctl stop firewalld
setenforce 0
iptables -F
#关闭firewalld、selinux清空iptables规则
yum  install bind  -y
#安装bind服务器提供DNS服务
vim /etc/name.conf
options{
listen-on port 53 { any; };
....
allow-query     { any; };
}
#修改DNS服务器配置文件,地址为any和修改允许所有人查询,修改内容如上保存退出
vim  /etc/name.named.rfc1912.zones
zone "lhj.com" IN {
        type master;
        file "lhj.com.zone";
        allow-update { none; };
};
#修改区域配置文件,在末尾添加以上内容。lhj.com为域名,lhj.com.zone为指定的域名数据文件
cd /var/named/
cp -a name.localhost  lhj.com.zone
#拷贝域名数据文件模板并命名为区域配置文件指定的名称进行修改
vim  lhj.com.zone

$TTL 1D
@       IN SOA  lhj.com. rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.lhj.com.
ns   IN A 192.168.30.20
@    IN MX 10 mail.lhj.com.
mail IN A 192.168.30.20
www  IN A 192.168.30.102
        A       127.0.0.1
        AAAA    ::1
#修改内容如上,mail地址指向postfixip地址、MX指向postfix域名、www测试地址
systemctl restart named
#重启named服务
vim  /etc/resolv.conf
#添加本机DNS服务器地址到resolv.conf文件首行
nameserver  192.168.30.20

nslookup  mail.lhj.com
#测试解析mail.lhj.com域名地址是否为192.168.30.20搭建DNS服务器完成

3. Deploy Postfix

mail-server执行:
yum -y install postfix
#安装postfix服务
vim /etc/postfix/main.cf
#编辑主配置文件搜索关键字修改以下内容
myhostname = mail.lhj.com 
#用来保存服务器的主机名称
mydomain = lhj.com 
#用来保存邮件域的名称
myorigin = $mydomain 
#定义发出邮件的域
inet_interfaces = all 
#定义网卡监听地址
mydestination = $myhostname, $mydomain 
#定义可接收邮件的主机名或域名列表
systemctl restart postfix
#重启postfix服务器使得配置生效
useradd test1
useradd test2
echo "123456" | passwd --stdin test1
echo "123456" | passwd --stdin test2
#创建2个测试用户并设置密码为123456

4. Deploy Dovecot

mail-server执行:
dovecot:开源的pop、imap邮件服务器
yum -y install dovecot
#安装 Dovecot 服务程序软件包
vim /etc/dovecot/dovecot.conf
#修改dovecot主配置文件
protocols = imap pop3 lmtp
#支持的协议包括:imap pop3 lmtp三种
disable_plaintext_auth = no
#关闭认证
vim /etc/dovecot/conf.d/10-mail.conf
#配置邮件格式及存储位置
mail_location = mbox:~/mail:INBOX=/var/mail/%u
#此行去掉注释,存储位置为用户家目录下home/test2/mail/.imap/INBOX下为日志和cache,以及/var/mail/用户名下为邮件内容
mkdir -p /home/test1/mail/.imap/INBOX
mkdir -p /home/test2/mail/.imap/INBOX
#为test1和test2用户创建保存邮件的目录

3. Use Foxmail to test

1. Modify the DNS server

Modify the DNS of windows to the DNS server address of this deployment, which is 192.168.30.20 

2. Foxmail login test account

3. Send a test email 

4. The server checks the mail

Guess you like

Origin blog.csdn.net/weixin_67287151/article/details/131552352