1. 程式人生 > >Postfix 郵件發送服務器搭建

Postfix 郵件發送服務器搭建

dep rac closed 發郵件 CP ssh table fig inf

搭建服務環境: Centos 6

配置域名hosts: mail.demonC6.com

1.清理系統自帶的郵件軟件

# rpm -qa | grep sendmail*
# rpm -e sendmail* --nodeps

2. 安裝postfix軟件

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 = all
114 #inet_interfaces = $myhostname
115 #inet_interfaces = $myhostname, localhost
116 #inet_interfaces = localhost

4) 修改收件人

164 mydestination = $myhostname,$mydomain
165 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
166 #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/8
265 #mynetworks = $config_directory/mynetworks
266 #mynetworks = hash:/etc/postfix/network_table

6) 修改轉發的郵件域名

296 relay_domains = $mydestination

7) 修改postfix 郵件別名 (下面兩項默認是開啟的,不用動)

385 #alias_maps = dbm:/etc/aliases
386 alias_maps = hash:/etc/aliases
387 #alias_maps = hash:/etc/aliases, nis:mail.aliases
388 #alias_maps = netinfo:/aliases
389
390 # The alias_database parameter specifies the alias database(s) that
391 # are built with "newaliases" or "sendmail -bi".  This is a separate
392 # configuration parameter, because alias_maps (see above) may specify
393 # tables that are not necessarily all under control by Postfix.
394 #
395 #alias_database = dbm:/etc/aliases
396 #alias_database = dbm:/etc/mail/aliases
397 alias_database = hash:/etc/aliases
398 #alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases

4 啟動postfix服務

# service postfix start

5 查看監聽端口

# netstat -anptu | grep :22
tcp        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

6 自我發郵件測試

[root@demon html]# echo  hello man | mail [email protected]
[root@demon html]# mail
Heirloom 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
& 1
Message  1:
From [email protected]  Sat May 12 11:37:49 2018
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Sat, 12 May 2018 11:37:49 +0800
To: [email protected]
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R

hello man
& d
& q

也可以通過telnet發郵件

[root@demon html]# telnet mail.demonC6.com 25
Trying 192.168.10.129...
Connected to mail.demonC6.com.
Escape character is ^].
220 mail.demonC6.com ESMTP Postfix
mail from: [email protected]
250 2.1.0 Ok
rcpt to: [email protected]
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Hello man, This is a test mail
.
250 2.0.0 Ok: queued as EAECD44917
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
[root@demon html]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 2 messages 2 new
>N  1 [email protected]      Sat May 12 11:42  14/513
 N  2 [email protected]      Sat May 12 11:43  14/515
& 2
Message  2:
From [email protected]  Sat May 12 11:43:31 2018
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Sat, 12 May 2018 11:43:10 +0800 (CST)
From: [email protected]
To: undisclosed-recipients:;
Status: R

Hello man, This is a test mail

& q
Held 2 messages in /var/spool/mail/root

Postfix 郵件發送服務器搭建