合 Linux配置postfix邮件服务器
简介
Postfix 是一种 电子邮件服务器,是 MTA(邮件传输代理)软件,Dovecot 是一个开源的 IMAP 和 POP3 邮件服务器,POP / IMAP 是 MUA 从邮件服务器中读取邮件时使用的协议。
postfix的产生是为了替代传统的sendmail。相较于sendmail,postfix在速度、性能和稳定性上都更胜一筹。
1)Sendmail或Postfix:实现邮件的接收和中转,即SMTP;
2)Dovecot:实现邮件的收取,即POP3和IMAP;
3)Foxmail:客户端收发邮件的工具。
安装
1 2 3 4 5 6 7 8 9 10 11 12 13 | yum -y install postfix sendmail* m4 dovecot bind* alternatives --config mta //请按1 [root@test mail]# alternatives --config mta There are 2 programs which provide 'mta'. Selection Command ----------------------------------------------- + 1 /usr/sbin/sendmail.postfix * 2 /usr/sbin/sendmail.sendmail |
修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [root@localhost ~]# vim /etc/postfix/main.cf 修改76:myhostname=mail.lhr.com //定义主机名 修改83:mydomain = lhr.com //定义域名 修改99:myorigin = $mydomain //从本机发出邮件的域名名称 修改116:inet_interfaces = all //监听的网卡接口 修改164:mydestination = $myhostname , $mydomain //设置可转发哪些主机的邮件 修改267: mynetworks = 0.0.0.0/0 # home_mailbox = Maildir/ #邮件目录,在用户的home下,默认位置/var/spool/mail/user or /var/mail/user [root@localhost ~]# vim /etc/dovecot/dovecot.conf 修改24:protocols = imap pop3 imtp //支持的电子邮件协议 修改48:login_trusted_networks = 0.0.0.0/0 //哪些人可以使用 listen = * ssl = no disable_plaintext_auth=no [root@localhost ~]#vim /etc/dovecot/conf.d/10-mail.conf 修改30:mail_location = mbox:~/mail:INBOX=/var/mail/%u echo '172.71.0.13 lhrdb mail.lhr.com lhr.com' >> /etc/hosts -- 检查配置文件是否有语法错误 postfix check |
创建邮件账号组及测试账号
1 2 3 4 5 | groupadd mailusers #添加邮件账号组 useradd -g mailusers -s /sbin/nologin lhr #创建测试账号lhr echo "lhr:lhr" | chpasswd useradd -g mailusers -s /sbin/nologin lhr1 echo "lhr1:lhr" | chpasswd |
重启服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | systemctl stop sendmail systemctl disable sendmail systemctl status sendmail systemctl restart postfix systemctl enable postfix systemctl status postfix systemctl restart dovecot systemctl enable dovecot systemctl status dovecot [root@test mail]# netstat -tulnp | grep 25 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 409311/master tcp6 0 0 :::25 :::* LISTEN 409311/master [root@test mail]# netstat -tulnp | grep 110 tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 409548/dovecot tcp6 0 0 :::110 :::* LISTEN 409548/dovecot [root@test mail]# netstat -tulnp | grep dovecot tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 409548/dovecot tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 409548/dovecot tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 409548/dovecot tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 409548/dovecot tcp6 0 0 :::110 :::* LISTEN 409548/dovecot tcp6 0 0 :::143 :::* LISTEN 409548/dovecot tcp6 0 0 :::993 :::* LISTEN 409548/dovecot tcp6 0 0 :::995 :::* LISTEN 409548/dovecot |
测试发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@test mail]# telnet mail.lhr.com 25 #连接mail服务器 Trying 172.71.0.13... Connected to mail.lhr.com. Escape character is '^]'. 220 mail.lhr.com ESMTP Postfix helo mail.lhr.com #声明本机的主机名 250 mail.lhr.com mail from:lhr@lhr.com #发件人 250 2.1.0 Ok rcpt to:lhr1@lhr.com #收件人 250 2.1.5 Ok data #开始编辑邮件的内容 354 End data with <CR><LF>.<CR><LF> subject: lhr test! # 主题 i am lhr . #以.结尾 250 2.0.0 Ok: queued as 2D4C2642D1C91 quit #退出 221 2.0.0 Bye Connection closed by foreign host. |
查看已发送的邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [root@test mail]# cd /var/spool/mail/ [root@test mail]# ll total 4 -rw-rw---- 1 lhr mail 0 Feb 27 09:46 lhr -rw-rw---- 1 lhr1 mail 416 Feb 27 09:48 lhr1 -rw-rw---- 1 pure-ftp mail 0 Feb 14 11:51 pure-ftp -rw-rw---- 1 rpc mail 0 May 27 2022 rpc [root@test mail]# more lhr [root@test mail]# more lhr1 From lhr@lhr.com Mon Feb 27 09:48:55 2023 Return-Path: <lhr@lhr.com> X-Original-To: lhr1@lhr.com Delivered-To: lhr1@lhr.com Received: from mail.lhr.com (test [172.71.0.13]) by mail.lhr.com (Postfix) with SMTP id 2D4C2642D1C91 for <lhr1@lhr.com>; Mon, 27 Feb 2023 09:48:16 +0800 (CST) Message-Id: <20230227014828.2D4C2642D1C91@mail.lhr.com> Date: Mon, 27 Feb 2023 09:48:16 +0800 (CST) From: lhr@lhr.com i am lhr [root@test mail]# |
测试给QQ邮箱发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@lhrdb ~]# telnet mail.lhr.com 25 Trying 172.18.0.14... Connected to mail.lhr.com. Escape character is '^]'. 220 mail.lhr.com ESMTP Postfix helo mail.lhr.com 250 mail.lhr.com mail from:lhr@lhr.com 250 2.1.0 Ok rcpt to:lhrbest@qq.com 250 2.1.5 Ok data 4 End data with <CR><LF>.<CR><LF> subject: lhr test! i am lhr . 250 2.0.0 Ok: queued as ADCB460D2820 quit 221 2.0.0 Bye Connection closed by foreign host. |
QQ邮箱即可收到邮件: