我的编程空间,编程开发者的网络收藏夹
学习永远不晚

postfix , dovecot 配置

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

postfix , dovecot 配置

(一)postfix  配置

 

 

一 配置dns

 

1 yum install bind -y

2 systemctl start named

3 vim /etc/named.conf

 

内容:

options {

//      listen-on port 53 { 127.0.0.1; };

//      listen-on-v6 port 53 { ::1; };

        directory       "/var/named";

        dump-file       "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        memstatistics-file "/var/named/data/named_mem_stats.txt";

//      allow-query     { localhost; };

 

dnssec-validation no;###是否合法,即是否可以充当公网上的dns,如果没有申请,就写no###

 

4 vim /etc/named.rfc1912.zones

 

内容:

zone "westos.com" IN {

        type master;

        file "westos.com.zone";

        allow-update { none; };

};

 

zone "qq.com" IN {

        type master;

        file "qq.com.zone";

        allow-update { none; };

};

 

5 cd /var/named/

6 cp -p named.localhost westos.com.zone

7 vim westos.com.zone

 

内容:

$TTL 1D

@       IN SOA  dns.westos.com. root.westos.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.westos.com.

dns             A       172.25.254.112

westos.com.     MX 1    172.25.254.112.

 

8 cp -p westos.com.zone qq.com.zone

9 vim qq.com.zone

 

内容:

$TTL 1D

@       IN SOA  dns.qq.com. root.qq.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.qq.com.

dns             A       172.25.254.112

qq.com.         MX 1    172.25.254.212.

 

10 systemctl restart named

11 systemctl stop firewalld.service

12 systemctl disable firewalld.service

 

 

二 基本电子邮件发送

 

1)postfix定义:

postfix提供smtp协议用来投递邮件,默认端口为25,日志在/var/log/maillog

MDA:“邮件发送代理“

2)重要的Postfix配置指令

1 myorigin :

重写本地发布的电子邮件,使其显示为来自该域。这样有助于确保响应返回入站邮件服务器

默认:myorigin = $myhostname

2 inet_interfaces:

控制Postfix侦听传入电子邮件的网络接口。如果设置为loopback-only,仅侦听127.0.0.1和::1,

如果设置为all,则侦听所有网络接口。还可以指定特定地址。

默认:inet_interfaces = localhost

3 mydestination:

收到地址为这些域的电子邮件将传递至MDA,以进行本地发送。

默认:mydestination = $myhostname, localhost.$mydomain, localhost

4 mynetworks

IP地址和网络的逗号分隔列表(采用CIDR表示法)。这些地址和网络可以通过此MTA转发至

任何位置,无需进一步身份验证。

默认:mynetworks = 127.0.0.0/8

 

3)邮件发送

发送邮件端:

 

1 vim /etc/postfix/main.cf###编辑postfix的主配置文件###

 

内容:

116 inet_interfaces = all###25端口开启的网络接口默认情况下,Postfix仅侦听来自本地主机的传入电子邮件。若要重新配置postfix以接收从远程主机发

送的本地邮件,必须设置inet_interfaces = all###

76 myhostname = westos-mail.westos.com###指定mta主机名称###

83 mydomain = westos.com###指定mta的域名###

99 myorigin = westos.com###指定邮件来源结尾(@后面的字符内容)

164 mydestination = $myhostname, $mydomain, localhost###接受邮件结尾字符的指定#

 

2 systemctl restart postfix.service###重启服务###

3 systemctl stop firewalld###关闭防火墙###

4 mail root@qq.com###发送邮件###

Subject: hello

hello

.###以“.”表示结束###

EOT

5  mailq(或postqueue -p)###显示已排队的所有传出邮件的列表###

6  postqueue -f###再次立即发送所有已排队的邮件###

 

 

接受邮件端:

1 vim /etc/postfix/main.cf

 

内容:

116 inet_interfaces = all                  ###25端口开启的网络接口。默认情况下,Postfix仅侦听来自本地主机的传入电子邮件。若要重新配置postfix以接收从远程主机发

送的本地邮件,必须设置inet_interfaces = all###

76 myhostname = qq-mail.westos.com         ###指定mta主机名称###

83 mydomain = qq.com   ###指定mta的域名###

99 myorigin = $mydomain                    ###指定邮件来源结尾(@后面的字符内容)

164 mydestination = $myhostname, $mydomain, localhost    ###接受邮件结尾字符的指定#

 

2 systemctl restart postfix.service

3 systemctl stop firewalld.service

4 mail###查看获得的邮件###

 

过程如下:

 

发邮件端:

[root@westos-mail named]# vim /etc/postfix/main.cf

 

116 inet_interfaces = all###25端口开启的网络接口###

76 myhostname = westos-mail.westos.com###指定mta主机名称###

 83 mydomain = westos.com###指定mta的域名###

99 myorigin = westos.com###指定邮件来源结尾(@后面的字符内容)

164 mydestination = $myhostname, $mydomain, localhost###接受邮件结尾字符的指定#

 

 

 

 

[root@westos-mail named]# systemctl restart postfix.service

[root@westos-mail named]# systemctl stop firewalld

[root@westos-mail named]# mail root@qq.com

Subject: hello

hello

.

EOT

[root@westos-mail named]# mailq

Mail queue is empty

[root@westos-mail named]#

 

 

接收邮件端:

[root@qq-mail ~]# vim /etc/postfix/main.cf

 

116 inet_interfaces = all                  ###25端口开启的网络接口###

76 myhostname = qq-mail.qq.com            ###指定mta主机名称###

83 mydomain = qq.com   ###指定mta的域名###

99 myorigin = $mydomain                    ###指定邮件来源结尾(@后面的字符内容)

164 mydestination = $myhostname, $mydomain, localhost    ###接受邮件结尾字符的指定#

 

[root@qq-mail ~]# systemctl restart postfix.service

[root@qq-mail ~]# systemctl stop firewalld.service

[root@qq-mail ~]# mailq

Mail queue is empty

You have mail in /var/spool/mail/root

[root@qq-mail ~]# cat /var/spool/mail/root

From root@westos.com  Sat May 20 03:13:41 2017

Return-Path: <root@westos.com>

X-Original-To: root@qq.com

Delivered-To: root@qq.com

Received: from westos-mail.westos.com (unknown [172.25.254.112])

by qq-mail.westos.com (Postfix) with ESMTP id 3442417E84B

for <root@qq.com>; Sat, 20 May 2017 03:13:41 -0400 (EDT)

Received: by westos-mail.westos.com (Postfix, from userid 0)

id CD43D2462AE; Sat, 20 May 2017 03:13:40 -0400 (EDT)

Date: Sat, 20 May 2017 03:13:40 -0400

To: root@qq.com

Subject: hello

User-Agent: Heirloom mailx 12.5 7/5/10

MIME-Version: 1.0

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

 

 

三 邮件别名

 

接收邮件端:

1 vim /etc/aliases

 

内容:

admin:          root

别名             真名

 

2 postalias /etc/aliases###立即生效###

3 systemctl restart postfix.service###重启服务###

 

测试:

发邮件端:

1 mail admin@qq.com

Subject: haa

haa

.

EOT

 

2 mailq

 

接收邮件端:

 mail

 

过程如下:

 

发邮件端:

[root@westos-mail ~]# mail admin@qq.com

Subject: haa

haa

.

EOT

[root@westos-mail ~]# mailq

Mail queue is empty

 

 

收邮件端:

 

[root@qq-mail ~]# vim /etc/aliases

 postfix , dovecot 配置

 

[root@qq-mail ~]# postalias /etc/aliases                 ###立即生效###

[root@qq-mail ~]# systemctl restart postfix.service

[root@qq-mail ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 3 messages 1 new 3 unread

 U  1 root                  Sat May 20 03:13  22/741   "hello"

 U  2 root                  Sat May 20 03:25  22/747   "world"

>N  3 root                  Sat May 20 04:09  21/731   "haa"

& q

Held 3 messages in /var/spool/mail/root

You have mail in /var/spool/mail/root

 

四 邮件群发

 

接收邮件端:

1 vim /etc/aliases

 

内容:

moreuser:       :include:/etc/postfix/moreuser

别名

 

2 vim /etc/postfix/moreuser

 

内容:

 

student

root

 

3  postalias /etc/aliases###立即生效###

4  systemctl restart postfix.service###重启服务###

 

测试:

发邮件端:

1 mail moreuser@qq.com

Subject: hello

kaa

.

EOT

2 mailq

 

收邮件端:

1 mail -u student                 ###查看student的邮件###

2  mail -u root                    ###查看root的邮件###

 

过程如下:

 

发邮件端:

[root@westos-mail ~]# mail moreuser@qq.com

Subject: hello

kaa

.

EOT

[root@westos-mail ~]# mailq

Mail queue is empty

 

 

 

[root@qq-mail ~]# vim /etc/aliases

postfix , dovecot 配置 

moreuser:       :include:/etc/postfix/moreuser

别名

 

[root@qq-mail ~]# vim /etc/postfix/moreuser

 

student

root

 

 

收邮件端:

[root@qq-mail ~]# postalias /etc/aliases

[root@qq-mail ~]# systemctl restart postfix.service

[root@qq-mail ~]# > /var/spool/mail/root

[root@qq-mail ~]# mail -u student                 ###查看student的邮件###

No mail for student

[root@qq-mail ~]# mail -u root                    ###查看root的邮件###

No mail for root

[root@qq-mail ~]# mail -u root

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/root": 1 message 1 new

>N  1 root                  Sat May 20 04:12  24/868   "hello"

& q

Held 1 message in /var/mail/root

[root@qq-mail ~]# mail -u student

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/student": 1 message 1 new

>N  1 root                  Sat May 20 04:12  24/871   "hello"

& q

Held 1 message in /var/mail/student

You have mail in /var/spool/mail/root

 

 

五 通过远程主机测试邮件服务

 

1 telnet 172.25.254.112 25###连接172.25.254.112的25端口###

Trying 172.25.254.112...

Connected to 172.25.254.112.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

ehlo hello                             ###跟112主机打个招呼##

250-westos-mail.westos.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:root@westos.com            ###邮件从root@westos.com发送###

250 2.1.0 Ok

rcpt to:root@qq.com                  ###邮件发到root@qq.com###

250 2.1.5 Ok

data                                 ###邮件内容###

354 End data with <CR><LF>.<CR><LF>

hello world

hai

.      ##以“.”表示结束###

250 2.0.0 Ok: queued as EEB672462AF

 

六 拒绝远程主机连接

 

1 postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"      #用smtpd_client_restrictions参数去检测/etc/postfix/access,但真正检测的是加密后的文件access.db####

 

2 vim /etc/postfix/main.cf   

3 vim /etc/postfix/access###编辑你拒绝连接的主机###

 

内容:

172.25.254.12 REJECT

 

4 postmap /etc/postfix/access   ###加密###

5 cd /etc/postfix/###加密后的文件在该目录下###

6 systemctl restart postfix.service

 

测试:

 

telnet 172.25.254.112 25

 

 

过程如下:

[root@westos-mail ~]# postconf -d | grep client###显示client的默认值##

broken_sasl_auth_clients = no

local_header_rewrite_clients = permit_inet_interfaces

parent_domain_matches_subdomains = debug_peer_list,fast_flush_domains,mynetworks,permit_mx_backup_networks,qmqpd_authorized_clients,relay_domains,smtpd_access_maps

postscreen_client_connection_count_limit = $smtpd_client_connection_count_limit

qmqpd_authorized_clients =

qmqpd_client_port_logging = no

relay_clientcerts =

smtpd_authorized_verp_clients = $authorized_verp_clients

smtpd_authorized_xclient_hosts =

smtpd_client_connection_count_limit = 50

smtpd_client_connection_rate_limit = 0

smtpd_client_event_limit_exceptions = ${smtpd_client_connection_limit_exceptions:$mynetworks}

smtpd_client_message_rate_limit = 0

smtpd_client_new_tls_session_rate_limit = 0

smtpd_client_port_logging = no

smtpd_client_recipient_rate_limit = 0

smtpd_client_restrictions =

unknown_client_reject_code = 450

[root@westos-mail ~]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"      #用smtpd_client_restrictions参数去检测/etc/postfix/access,但真正检测的是加密后的文件access.db####

[root@westos-mail ~]# vim /etc/postfix/main.cf

postfix , dovecot 配置

[root@westos-mail ~]# vim /etc/postfix/access

postfix , dovecot 配置

[root@westos-mail ~]# vim /etc/postfix/access

[root@westos-mail ~]# postmap /etc/postfix/access   ###加密###

[root@westos-mail ~]# ls

anaconda-ks.cfg  Documents  Music     Public     Videos

Desktop          Downloads  Pictures  Templates

[root@westos-mail ~]# cd /etc/postfix/

[root@westos-mail postfix]# ls

access     generic        master.cf  virtual

access.db  header_checks  relocated

canonical  main.cf        transport

[root@westos-mail postfix]#

 

测试:

 

[root@foundation12 Desktop]# telnet 172.25.254.112 25

Trying 172.25.254.112...

Connected to 172.25.254.112.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:root@westos.com

250 2.1.0 Ok

rcpt to:root@qq.com

554 5.7.1 <unknown[172.25.254.12]>: Client host rejected: Access denied

q

502 5.5.2 Error: command not recognized

quit

221 2.0.0 Bye

Connection closed by foreign host.

[root@foundation12 Desktop]#

 

 

七 限制远程主机连接用户发送

 

被连接的主机:

1 postconf -d | grep sender###查看参数###

2 postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"###用smtpd_sender_restrictions参数去检测

/etc/postfix/sender文件###

3 vim /etc/postfix/sender###编辑文件###

内容:

student@westos.com      REJECT###拒绝student@westos.com用户发送###

4 postmap /etc/postfix/sender###加密###

5 cd /etc/postfix/###加密后的文件在该目录下

6 systemctl restart postfix.service###重启服务###

 

过程如下:

[root@westos-mail ~]# postconf -d | grep sender

address_verify_sender = $double_bounce_sender

address_verify_sender_dependent_default_transport_maps = $sender_dependent_default_transport_maps

address_verify_sender_dependent_relayhost_maps = $sender_dependent_relayhost_maps

address_verify_sender_ttl = 0s

canonical_classes = envelope_sender, envelope_recipient, header_sender, header_recipient

double_bounce_sender = double-bounce

lmtp_sender_dependent_authentication = no

masquerade_classes = envelope_sender, header_sender, header_recipient

proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps

sender_bcc_maps =

sender_canonical_classes = envelope_sender, header_sender

sender_canonical_maps =

sender_dependent_default_transport_maps =

sender_dependent_relayhost_maps =

smtp_sender_dependent_authentication = no

smtpd_reject_unlisted_sender = no

smtpd_sender_login_maps =

smtpd_sender_restrictions =

unverified_sender_defer_code = 450

unverified_sender_reject_code = 450

unverified_sender_reject_reason =

unverified_sender_tempfail_action = $reject_tempfail_action

[root@westos-mail ~]# postconf -e "smtpd_sender_restrictions = check_sender_acess hash:/etc/postfix/sender"

[root@westos-mail ~]# vim /etc/postfix/sender

[root@westos-mail ~]# postmap /etc/postfix/sender

[root@westos-mail ~]# systemctl restart postfix.service

[root@westos-mail ~]# systemctl start named

[root@westos-mail ~]# systemctl stop firewalld

[root@westos-mail postfix]# ls

access     canonical  header_checks  master.cf  sender     transport

access.db  generic    main.cf        relocated  sender.db  virtual

 

测试:

[kiosk@foundation12 Desktop]$ telnet 172.25.254.112 25

Trying 172.25.254.112...

Connected to 172.25.254.112.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:student@westos.com

250 2.1.0 Ok

rcpt to:root@westos.com

554 5.7.1 <unknown[172.25.254.12]>: Client host rejected: Access denied

quit

221 2.0.0 Bye

Connection closed by foreign host.

[kiosk@foundation12 Desktop]$

 

八 限制用户接收

 

接受邮件端:

1 postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

2 vim /etc/postfix/recip

 

内容:

 

westos@westos.com       REJECT###限制westos@wests.com用户接收###

 

 

3 postmap /etc/postfix/recip ###加密###

4 systemctl restart postfix.service

 

 

过程如下:

[root@westos-mail ~]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

[root@westos-mail ~]# vim /etc/postfix/recip

 

westos@westos.com       REJECT

 

 

[root@westos-mail ~]# postmap /etc/postfix/recip

[root@westos-mail ~]# systemctl restart postfix.service

 

测试:

[kiosk@foundation12 Desktop]$ telnet 172.25.254.112 25

Trying 172.25.254.112...

Connected to 172.25.254.112.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:westos@westos.com

250 2.1.0 Ok

rcpt to:root@westos.com

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

hello

hello

.

250 2.0.0 Ok: queued as D00F9EAC27

mail from:root@westos.com

250 2.1.0 Ok

rcpt to:westos@westos.com

554 5.7.1 <westos@westos.com>: Recipient address rejected: Access denied

421 4.4.2 westos-mail.westos.com Error: timeout exceeded

Connection closed by foreign host.

 

 

九 入站地址转换

 

邮件发送方:

1 postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

2 vim /etc/postfix/generic

3 postmap /etc/postfix/generic

 

westos@westos.com       hello@haa.com

真实用户虚拟用户

4 postmap /etc/postfix/generic###加密###

测试:

su - westos

mail root@qq.com

 

 

 

过程如下:

邮件发送方:

[root@westos-mail ~]# postconf -d | grep generic

lmtp_generic_maps =

proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps

smtp_generic_maps =

[root@westos-mail ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

[root@westos-mail ~]# vim /etc/postfix/generic

[root@westos-mail ~]# postmap /etc/postfix/generic

 

 

测试:

邮件发送方:

[root@westos-mail ~]# su - westos

[westos@westos-mail ~]$ mail root@qq.com

Subject: hello hello

hello

.

EOT

[westos@westos-mail ~]$ mailq

Mail queue is empty

 

 

邮件接收方:

[root@qq-mail ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 3 messages 1 new

    1 root                  Sat May 20 04:12  25/879   "hello"

    2 root@westos.com       Sat May 20 04:36  15/510   

>N  3 hello@haa.com         Sat May 20 22:32  21/725   "hello hello"

& 3

Message  3:

From hello@haa.com  Sat May 20 22:32:21 2017

Return-Path: <hello@haa.com>###名字发生了变化###

X-Original-To: root@qq.com

Delivered-To: root@qq.com

Date: Sat, 20 May 2017 22:32:23 -0400

To: root@qq.com

Subject: hello hello

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: hello@haa.com

Status: R

 

hello

 

&

 

 

十 出站地址转换

 

1) 先做dns解析:

1 vim /etc/named.rfc1912.zones

内容:

zone "haa.com" IN {

        type master;

        file "haa.com.zone";

        allow-update { none; };

};

 

2 cd /var/named/

3 cp -p qq.com.zone haa.com.zone

4 vim haa.com.zone

 

内容:

 

$TTL 1D

@       IN SOA  dns.haa.com. root.haa.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.haa.com.

dns             A       172.25.254.112

haa.com.        MX 1    172.25.254.112.##为真实名字主机的ip###

~                                             

 

5 systemctl restart named

 

过程如下:

[root@westos-mail westos]# vim /etc/named.rfc1912.zones

 

 

zone "haa.com" IN {

        type master;

        file "haa.com.zone";

        allow-update { none; };

};

 

 

[root@westos-mail named]# cd /var/named/

[root@westos-mail named]# ls

data     named.ca     named.localhost  qq.com.zone  westos.com.zone

dynamic  named.empty  named.loopback   slaves

[root@westos-mail named]# cp -p qq.com.zone haa.com.zone

[root@westos-mail named]# vim haa.com.zone

 

$TTL 1D

@       IN SOA  dns.haa.com. root.haa.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.haa.com.

dns             A       172.25.254.112

haa.com.        MX 1    172.25.254.112.

~                                             

[root@westos-mail named]# systemctl restart named

 

2)配置

1 postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

2 vim /etc/postfix/virtual

 

内容:

hello@haa.com   westos@westos.com

别名真名

 

3 postmap /etc/postfix/virtual###加密###

4 systemctl restart postfix.service

 

过程如下:

 

 

[root@westos-mail named]# postconf -d | grep virtual

address_verify_virtual_transport = $virtual_transport

propagate_unmatched_extensions = canonical, virtual

proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps

unknown_virtual_alias_reject_code = 550

unknown_virtual_mailbox_reject_code = 550

virtual_alias_domains = $virtual_alias_maps

virtual_alias_expansion_limit = 1000

virtual_alias_maps = $virtual_maps

virtual_alias_recursion_limit = 1000

virtual_delivery_slot_cost = $default_delivery_slot_cost

virtual_delivery_slot_discount = $default_delivery_slot_discount

virtual_delivery_slot_loan = $default_delivery_slot_loan

virtual_destination_concurrency_failed_cohort_limit = $default_destination_concurrency_failed_cohort_limit

virtual_destination_concurrency_limit = $default_destination_concurrency_limit

virtual_destination_concurrency_negative_feedback = $default_destination_concurrency_negative_feedback

virtual_destination_concurrency_positive_feedback = $default_destination_concurrency_positive_feedback

virtual_destination_rate_delay = $default_destination_rate_delay

virtual_destination_recipient_limit = $default_destination_recipient_limit

virtual_extra_recipient_limit = $default_extra_recipient_limit

virtual_gid_maps =

virtual_initial_destination_concurrency = $initial_destination_concurrency

virtual_mailbox_base =

virtual_mailbox_domains = $virtual_mailbox_maps

virtual_mailbox_limit = 51200000

virtual_mailbox_lock = fcntl, dotlock

virtual_mailbox_maps =

virtual_minimum_delivery_slots = $default_minimum_delivery_slots

virtual_minimum_uid = 100

virtual_recipient_limit = $default_recipient_limit

virtual_recipient_refill_delay = $default_recipient_refill_delay

virtual_recipient_refill_limit = $default_recipient_refill_limit

virtual_transport = virtual

virtual_uid_maps =

[root@westos-mail named]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

[root@westos-mail named]# vim /etc/postfix/virtual

postfix , dovecot 配置 

 

hello@haa.com   westos@westos.com

别名真名

 

 

[root@westos-mail named]# postmap /etc/postfix/virtual###加密###

[root@westos-mail named]# systemctl restart postfix.service

 

 

 

测试:

邮件发送端:

1 mail hello@haa.com###发邮件###

2 mailq

 

邮件接收端:

mail

 

过程如下:

[root@westos-mail named]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/westos": 1 message 1 new

>N  1 root                  Sat May 20 22:42  21/719   "hai"

& 1

Message  1:

From root@qq.com  Sat May 20 22:42:59 2017

Return-Path: <root@qq.com>

X-Original-To: hello@haa.com

Delivered-To: westos@westos.com

Date: Sat, 20 May 2017 22:42:58 -0400

To: hello@haa.com

Subject: hai

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: root@qq.com (root)

Status: R

 

hai

 

&

 

 

[root@qq-mail ~]# mail hello@haa.com###发邮件###

Subject: hai

hai

.

EOT

[root@qq-mail ~]# mailq

Mail queue is empty

[root@qq-mail ~]#

 

 

 

(二)dovecot配置

 

一 定义:

dovecot用来提供收件协议。

协议:端口:

pop3110

imap143

imaps993

pop3s995

给定用户名称,用户密码,dovecot程序带我们去看这个用户的邮件文件

 

二 配置

1 vim /etc/dovecot/dovecot.conf###谁能够访问并且通过验证###

内容:

 

24 protocols = imap pop3 lmtp###打开收件协议###

48 login_trusted_networks = 0.0.0.0/0###允许所有人连接###

49 disable_plaintext_auth = no###支持明文###

 

2 vim /etc/dovecot/conf.d/10-mail.conf###带用户去看什么文件###

内容:

 

30 mail_location = mbox:~/mail:INBOX=/var/mail/%u

 

3 mkdir /etc/skel/mail/.imap -p###在用户骨架文件里建立目录,则新建的用户均有该目录###

4 touch /etc/skel/mail/.imap/INBOX

5 mkdir /home/westos/mail/.imap -p###如果是原先就存在的用户,则要另外建该目录,因为用户骨架文件中没有该用户的这个目录###

6 touch /home/westos/mail/.imap/INBOX

 

过程如下:

[root@westos-mail ~]# yum install dovecot -y

[root@westos-mail ~]# systemctl start dovecot

[root@westos-mail ~]# netstat -anplte | grep dovecot

tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      0          92793      5989/dovecot        

tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      0          92769      5989/dovecot        

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      0          92767      5989/dovecot        

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      0          92791      5989/dovecot        

tcp6       0      0 :::993                  :::*                    LISTEN      0          92794      5989/dovecot        

tcp6       0      0 :::995                  :::*                    LISTEN      0          92770      5989/dovecot        

tcp6       0      0 :::110                  :::*                    LISTEN      0          92768      5989/dovecot        

tcp6       0      0 :::143                  :::*                    LISTEN      0          92792      5989/dovecot        

[root@westos-mail ~]# vim /etc/dovecot/dovecot.conf

 postfix , dovecot 配置

postfix , dovecot 配置

postfix , dovecot 配置




[root@westos-mail ~]# vim /etc/dovecot/conf.d/10-mail.conf

 postfix , dovecot 配置


 

[root@westos-mail ~]# systemctl restart dovecot.service

[root@westos-mail ~]# mkdir /etc/skel/mail/.imap -p

[root@westos-mail ~]# touch /etc/skel/mail/.imap/INBOX

[root@westos-mail ~]# passwd westos

Changing password for user westos.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

[root@westos-mail ~]# mkdir /home/westos/mail/.imap -p

[root@westos-mail ~]# touch /home/westos/mail/.imap/INBOX

 

 

 

测试:

mutt -f pop://westos@172.25.254.112

 

postfix , dovecot 配置

postfix , dovecot 配置

postfix , dovecot 配置

 

 

 

三 profix+mysql

 

1)准备工作:

1 yum install httpd php php-mysql.x86_64 mariadb-server.x86_64 -y

2 vim /etc/my.cnf

 

内容:

skip-networking = 1

 

3 mysql_secure_installation ###数据库初始化###

4 cd /var/www/html/

5 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2

6 mv phpMyAdmin-3.4.0-all-languages/ myadmin

7 cd myadmin/

8 cp config.sample.inc.php config.inc.php

9 vim config.inc.php

postfix , dovecot 配置

10 systemctl restart httpd

11 create user postuser@localhost identified by 'postuser';

12 create db ,usermessage,dbuser

 

postfix , dovecot 配置

postfix , dovecot 配置

postfix , dovecot 配置


2)配置

 

1 cd /etc/postfix/

2 vim mailuser.cf###用户名称查询###

 

内容:

hosts = localhost###数据库所在主机###

user = postuser###登入数据库的用户###

password = postuser###登入数据库的密码###

dbname = email###postfix要查询的库的名称###

table = emailuser###postfix要查询的表的名称###

select_field = username###postfix要查询的字段###

where_field = username###用户给定postfix的查询条件###

 

3 cp mailuser.cf maildomain.cf###用户域名查询###

4 vim maildomain.cf

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = domain

where_field = domain

 

5 cp mailuser.cf mailbox.cf

6 vim mailbox.cf ###用户邮箱查询###

 

 

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = maildir

where_field = username

 

7 postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf ###查看是否会输出用户名,若输出,则说明写对了###

8 postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf

9 postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf

 

3)postfix配置

1 groupadd -g 666 vmail

2 useradd  -s /sbin/nologin -u 666 vmail -g 666

3 postconf -d | grep virtual

4 postconf -e "virtual_mailbox_base = /home/vmail"###设定虚拟用户的邮件目录###

5 postconf -e "virtual_uid_maps = static:666"###虚拟用户建立文件的uid###

6 postconf -e "virtual_gid_maps = static:666"###虚拟用户的建立文件的gid###

7 postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"

8 postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"

9 postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/maildomain.cf"

测试是否写对:若是存在则说明写对了

ll /etc/postfix/mailuser.cf

ll /etc/postfix/mailbox.cf

ll /etc/postfix/maildomain.cf

 

 

测试:

mail lee@lee.com###看能否使用数据库里的用户发送邮件###

 

 

过程如下:

[root@westos-mail myadmin]# cd /etc/postfix/

[root@westos-mail postfix]# vim mailuser.cf

 

 

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = username

where_field = username

 

 

 

 

 

[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:mailuser.cf

postmap: fatal: bad string length 0 < 1: mailuser.cf_dbname =

[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf

[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf

[root@westos-mail postfix]# vim mailuser.cf

[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf

lee@lee.com

[root@westos-mail postfix]# cp mailuser.cf maildomain.cf

[root@westos-mail postfix]# vim maildomain.cf

 

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = domain

where_field = domain

~                        

 

 

 

[root@westos-mail postfix]# postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf

lee.com,lee.com

[root@westos-mail postfix]# cp mailuser.cf mailbox.cf

[root@westos-mail postfix]# vim mailbox.cf

 

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = maildir

where_field = username

 

 

 

 

[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf

postmap: warning: mysql query failed: Unknown column 'madir' in 'field list'

postmap: fatal: table mysql:/etc/postfix/mailbox.cf: query error: Success

[root@westos-mail postfix]# vim mailbox.cf

[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf

/mnt/lee.com/lee

[root@westos-mail postfix]#

 

 

 

 

 

 

 

[root@westos-mail ~]# groupadd -g 666 vmail

[root@westos-mail ~]# useradd  -s /sbin/nologin -u 666 vmail -g 666

[root@westos-mail ~]# id vmail

uid=666(vmail) gid=666(vmail) groups=666(vmail)

[root@westos-mail ~]# postconf -d | grep virtual

address_verify_virtual_transport = $virtual_transport

propagate_unmatched_extensions = canonical, virtual

proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps

unknown_virtual_alias_reject_code = 550

unknown_virtual_mailbox_reject_code = 550

virtual_alias_domains = $virtual_alias_maps

virtual_alias_expansion_limit = 1000

virtual_alias_maps = $virtual_maps

virtual_alias_recursion_limit = 1000

virtual_delivery_slot_cost = $default_delivery_slot_cost

virtual_delivery_slot_discount = $default_delivery_slot_discount

virtual_delivery_slot_loan = $default_delivery_slot_loan

virtual_destination_concurrency_failed_cohort_limit = $default_destination_concurrency_failed_cohort_limit

virtual_destination_concurrency_limit = $default_destination_concurrency_limit

virtual_destination_concurrency_negative_feedback = $default_destination_concurrency_negative_feedback

virtual_destination_concurrency_positive_feedback = $default_destination_concurrency_positive_feedback

virtual_destination_rate_delay = $default_destination_rate_delay

virtual_destination_recipient_limit = $default_destination_recipient_limit

virtual_extra_recipient_limit = $default_extra_recipient_limit

virtual_gid_maps =

virtual_initial_destination_concurrency = $initial_destination_concurrency

virtual_mailbox_base =

virtual_mailbox_domains = $virtual_mailbox_maps

virtual_mailbox_limit = 51200000

virtual_mailbox_lock = fcntl, dotlock

virtual_mailbox_maps =

virtual_minimum_delivery_slots = $default_minimum_delivery_slots

virtual_minimum_uid = 100

virtual_recipient_limit = $default_recipient_limit

virtual_recipient_refill_delay = $default_recipient_refill_delay

virtual_recipient_refill_limit = $default_recipient_refill_limit

virtual_transport = virtual

virtual_uid_maps =

[root@westos-mail ~]# postconf -e "virtual_mailbox_base = /home/vmail"

[root@westos-mail ~]# postconf -e "virtual_uid_maps = static:666"

[root@westos-mail ~]# postconf -e "virtual_gid_maps = static:666"

[root@westos-mail ~]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"

[root@westos-mail ~]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfi/maildomain.cf

[root@westos-mail ~]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"

[root@westos-mail ~]# ll /etc/postfix/mailuser.cf

-rw-r--r--. 1 root root 134 May 21 04:06 /etc/postfix/mailuser.cf

[root@westos-mail ~]# ll /etc/postfix/mailbox.cf

-rw-r--r--. 1 root root 133 May 21 04:21 /etc/postfix/mailbox.cf

[root@westos-mail ~]# ll /etc/postfix/maildomain.cf

-rw-r--r--. 1 root root 130 May 21 04:19 /etc/postfix/maildomain.cf

[root@westos-mail ~]# cd /home/vmail/

[root@westos-mail vmail]# ls

mail

[root@westos-mail vmail]# mail lee@lee.com

Subject: hello

hello hello

.

EOT

[root@westos-mail vmail]# mailq

Mail queue is empty

[root@westos-mail vmail]# ls

lee.com  mail

[root@westos-mail vmail]# cd lee.com/

[root@westos-mail lee.com]# ls

lee

[root@westos-mail lee.com]# cd lee/

[root@westos-mail lee]# ls

cur  new  tmp

[root@westos-mail lee]# cd new/

[root@westos-mail new]# cat new/

cat: new/: No such file or directory

[root@westos-mail new]# cd ne

-bash: cd: ne: No such file or directory

[root@westos-mail new]# cd new/

-bash: cd: new/: No such file or directory

[root@westos-mail new]#

[root@westos-mail new]# ls

1495357341.Vfd01I30059aaM65037.westos-mail.westos.com

[root@westos-mail new]# cat 1495357341.Vfd01I30059aaM65037.westos-mail.westos.com

Return-Path: <root@westos.com>

X-Original-To: lee@lee.com

Delivered-To: lee@lee.com

Received: by westos-mail.westos.com (Postfix, from userid 0)

id DF62F273AC2; Sun, 21 May 2017 05:02:20 -0400 (EDT)

Date: Sun, 21 May 2017 05:02:20 -0400

To: lee@lee.com

Subject: hello

User-Agent: Heirloom mailx 12.5 7/5/10

MIME-Version: 1.0

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

Message-Id: <20170521090220.DF62F273AC2@westos-mail.westos.com>

From: root@westos.com (root)

 

hello hello


免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

postfix , dovecot 配置

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

邮件系统架设postfix+dovecot+mysql+postfixadmin+roundcube

这篇文章介绍一个实现Web收发的邮件系统方案,利用postfix作为SMTP服务器,实现邮件的发送与接收,使用dovecot作为IMAP服务器,roundcube作为web MUA(邮件用户代理),实现web在线邮件发送与接收。而postf
2022-05-28

linux 安装配置 postfix+p

首先介绍下环境与提前准备。            postfix      192.168.6.121    1.在自己的域名服务商添加 域名 与A记录,我的是内部测试也就在自己的内部DNS 上添加了 以下记录               
2023-01-31

postfix安装以及配置3

邮件服务器系统的smtp服务器,在邮件服务器系统中充当MTA角色1 安装Postfix(1)   创建相关的用户和组否则make install得时候会报错#groupadd postfix -g 501#groupadd postdrop
2023-01-31

CentOS中怎么用Dovecot和Postfix搭建邮件服务器

搭建邮件服务器需要以下步骤:安装Dovecot和Postfix:sudo yum install dovecot postfix配置Postfix:编辑主配置文件/etc/postfix/main.cf,设置以下参数:myhostname
CentOS中怎么用Dovecot和Postfix搭建邮件服务器
2024-04-19

详解/etc/postfix下 main.cf 配置文件

postconf -n#别名数据库(postalias/newaliases 命令生成) alias_database = hash:/etc/postfix/aliases #别名表,列出local mda 所使用的别名数据库 ali
2022-06-04

使用ubuntu搭建公网个人邮件服务器(基于postfix,dovecot,mysql)

前言 本教程基于 ubuntu 18.04(其他的 linux 理论上也是可以的,知识安装的软件包不一样)。用到的主要软件为:postfix,dovecot,mysql.废话不多说,下面是教程: 前置条件mysql 数据库。本教程中使用 m
2022-06-04

Linux中如何配置Postfix邮件发送

今天小编给大家分享一下Linux中如何配置Postfix邮件发送的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。部署DNS服务
2023-06-28

Linux下如何安装Postfix邮件WebMail配置

这篇文章给大家分享的是有关Linux下如何安装Postfix邮件WebMail配置的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。ExtmailExtmail 是一个以perl语言编写,面向大容量/ISP级应用,免
2023-06-27

Linux怎么配置Postfix邮件服务器

这篇文章主要介绍了Linux怎么配置Postfix邮件服务器的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Linux怎么配置Postfix邮件服务器文章都会有所收获,下面我们一起来看看吧。步骤 1)更新系统第一
2023-06-28

Linux下配置Dovecot常见错误及解决办法

Error: doveconf: Fatal: Error in configuration file /etc/dovecot/dovecot.conf: protocols: Unknown protocol: sieveGroupwa
2022-05-13

CentOS 8中怎么配置Postfix邮件服务器

本篇文章给大家分享的是有关CentOS 8中怎么配置Postfix邮件服务器,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。步骤 1)更新系统第一步是确保系统软件包是最新的。为此
2023-06-16

Linux下如何安装Postfix邮件认证配置

小编给大家分享一下Linux下如何安装Postfix邮件认证配置,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!Postfix+Dovecot+Sasl工作原理1.
2023-06-27

【Linux】邮件服务器搭建 postfix+dovecot+mysql (终极版 超详细 亲测多遍无问题)

🍁博主简介   🏅云计算领域优质创作者   🏅华为云开发者社区专家博主   🏅阿里云开发者社区专家博主 💊交流社区:运维交流社区 欢迎大家的加入!
2023-08-16

Linux系统下怎么安装和配置postfix邮件服务器

本篇内容介绍了“Linux系统下怎么安装和配置postfix邮件服务器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!一,安装postfix,
2023-06-12

如何在CentOS 8上安装和配置Postfix邮件服务器

如何在CentOS 8上安装和配置Postfix邮件服务器,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Postfix是一个开源的电子邮件服务器,。Postfi
2023-06-28

怎么在Linux中安装配置Postfix来搭建邮件发送服务

这篇文章主要介绍“怎么在Linux中安装配置Postfix来搭建邮件发送服务”,在日常操作中,相信很多人在怎么在Linux中安装配置Postfix来搭建邮件发送服务问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答
2023-06-12

如何在CentOS8上安装和配置Postfix邮件服务器的方法示例

Postfix 是一个自由开源的 MTA(邮件传输代理),用于在 linux 系统上路由或传递电子邮件。在本指南中,你将学习如何在 CentOS 8 上安装和配置 Postfix。 实验室设置:系统:CentOS 8 服务器IP 地址:19
2022-06-04

编程热搜

目录