Postfix 邮件发送服务器搭建

Posted Dëm0n

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postfix 邮件发送服务器搭建相关的知识,希望对你有一定的参考价值。

搭建服务环境: 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 自我发邮件测试

[[email protected] html]# echo  hello man | mail [email protected]
[[email protected] 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发邮件

[[email protected] 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
[[email protected] 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 邮件发送服务器搭建的主要内容,如果未能解决你的问题,请参考以下文章

linux redhat6.5 中 搭建Postfix邮件服务器

centos7搭建postfix邮件服务器

Centos 下搭建postfix和Dovecot的邮箱服务系统

Centos 下搭建postfix和Dovecot的邮箱服务系统

Redhat6.5中搭建postfix邮箱服务

linux搭建postfix邮件服务