原文链接:
1.清理系统自带的邮件软件
# rpm -qa | grep sendmail*# rpm -e sendmail* --nodeps
2. 安装postfix 和 dovecot 软件
postfix 是发送邮件服务器,可以将邮件发送到该服务器上, 监听端口为 25(SMTP)
dovecot 是接受邮件服务器, 可以到服务器上取回自己的邮件, 监听端口是 110(pop3)
yum -y install postfix*
3. 配置postfix
vim /etc/postfix/main.cf
需要修改的配置如下几项,红色表示需要开启), 蓝色表示需要注释关闭:
1) 更改邮件主机名和域名
75 myhostname = mail.demonC6.com 76 #myhostname = virtual.domain.tld 77
78 # The mydomain parameter specifies the local internet domain name. 79 # The default is to use $myhostname minus the first component. 80 # $mydomain is used as a default value for many other configuration 81 # parameters. 82 # 83 mydomain = demonC6.com
2) 修改组织
94 # For the sake of consistency between sender and recipient addresses, 95 # myorigin also specifies the default domain name that is appended 96 # to recipient addresses that have no @domain part. 97 # 98 myorigin = $myhostname
99 myorigin = $mydomain
3) 修改监听的地址
113 inet_interfaces = all114 #inet_interfaces = $myhostname115 #inet_interfaces = $myhostname, localhost116 #inet_interfaces = localhost
4) 修改收件人
164 mydestination = $myhostname,$mydomain165 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain166 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,167 # mail.$mydomain, www.$mydomain, ftp.$mydomain
5) 修改网卡所在的网段
264 mynetworks = 192.168.10.0/24, 127.0.0.0/8265 #mynetworks = $config_directory/mynetworks266 #mynetworks = hash:/etc/postfix/network_table
6) 修改转发的邮件域名
296 relay_domains = $mydestination
7) 修改postfix 邮件别名 (下面两项默认是开启的,不用动)
385 #alias_maps = dbm:/etc/aliases386 alias_maps = hash:/etc/aliases387 #alias_maps = hash:/etc/aliases, nis:mail.aliases388 #alias_maps = netinfo:/aliases389390 # The alias_database parameter specifies the alias database(s) that391 # are built with "newaliases" or "sendmail -bi". This is a separate392 # configuration parameter, because alias_maps (see above) may specify393 # tables that are not necessarily all under control by Postfix.394 #395 #alias_database = dbm:/etc/aliases396 #alias_database = dbm:/etc/mail/aliases397 alias_database = hash:/etc/aliases398 #alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
4 启动postfix服务,查看监听端口
# service postfix start
# netstat -anptu | grep :22tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2276/sshd
tcp 0 40 192.168.10.129:22 192.168.10.1:56933 ESTABLISHED 6350/sshd
tcp 0 0 :::22 :::* LISTEN 2276/sshd
5 自我发邮件测试
[root@demon html]# echo hello man | mail root@demonC6.com[root@demon html]# mailHeirloom Mail version 12.4 7/29/08. Type ? for help."/var/spool/mail/root": 1 message 1 new>N 1 root Sat May 12 11:37 17/543& 1Message 1:
From root@demonC6.com Sat May 12 11:37:49 2018Return-Path: <root@demonC6.com>X-Original-To: root@demonC6.com
Delivered-To: root@demonC6.com
Date: Sat, 12 May 2018 11:37:49 +0800To: root@demonC6.com
User-Agent: Heirloom mailx 12.4 7/29/08Content-Type: text/plain; charset=us-ascii
From: root@demonC6.com (root)
Status: R
hello man& d& q
也可以通过telnet发邮件
[root@demon html]# telnet mail.demonC6.com 25Trying 192.168.10.129...
Connected to mail.demonC6.com.
Escape character is '^]'.220 mail.demonC6.com ESMTP Postfixmail from: root@demonC6.com250 2.1.0 Okrcpt to: root@demonC6.com250 2.1.5 Okdata354 End data with <CR><LF>.<CR><LF>Hello man, This is a test mail
.250 2.0.0 Ok: queued as EAECD44917quit221 2.0.0 Bye
Connection closed by foreign host.You have new mail in /var/spool/mail/root[root@demon html]# mailHeirloom Mail version 12.4 7/29/08. Type ? for help."/var/spool/mail/root": 2 messages 2 new>N 1 root@demonC6.com Sat May 12 11:42 14/513
N 2 root@demonC6.com Sat May 12 11:43 14/515& 2Message 2:
From root@demonC6.com Sat May 12 11:43:31 2018Return-Path: <root@demonC6.com>X-Original-To: root@demonC6.com
Delivered-To: root@demonC6.com
Date: Sat, 12 May 2018 11:43:10 +0800 (CST)
From: root@demonC6.com
To: undisclosed-recipients:;
Status: R
Hello man, This is a test mail& qHeld 2 messages in /var/spool/mail/root
6 配置 dovecot 并启动服务
# vim /etc/dovecot/dovecot.conf
将下面这一行注释去掉,开启即可
20 protocols = imap pop3 lmtp
启动pop3服务
# service dovecot start
# netstat -anptu | grep 110tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 19822/dovecot
tcp 0 0 :::110 :::* LISTEN 19822/dovecot
创建两个测试用户,测试相互收发邮件
# useradd user1 && echo 123456 | passwd --stdin user1# useradd user2 && echo 123456 | passwd --stdin user2
user1 给 user2 发送邮件
# su - user1
$ echo "user1 -> user2" | mail user2@demonC6.com
$ su user2$ mail -u user2Heirloom Mail version 12.4 7/29/08. Type ? for help."/var/mail/user2": 1 message 1 new>N 1 user1@demonC6.com Sat May 12 12:11 17/550& 1Message 1:
From user1@demonC6.com Sat May 12 12:11:58 2018Return-Path: <user1@demonC6.com>X-Original-To: user2@demonC6.com
Delivered-To: user2@demonC6.com
Date: Sat, 12 May 2018 12:11:58 +0800To: user2@demonC6.com
User-Agent: Heirloom mailx 12.4 7/29/08Content-Type: text/plain; charset=us-ascii
From: user1@demonC6.com
Status: Ruser1 -> user2& q