mail postfix postfix+mariadb


配置DNS

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

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

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

 

 

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

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

17 //      allow-query     { localhost; };

32         dnssec-validation no;

 

 

[root@westos-mail ~]# 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; };

};

 

 

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

[root@westos-mail named]# ls

data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves

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

[root@westos-mail named]# 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.104

westos.com.     MX 1    172.25.254.104.

 

 

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

[root@westos-mail named]# 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.104

qq.com.         MX 1    172.25.254.204.

 

 

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

[root@westos-mail named]# vim /etc/resolv.conf

 

nameserver 172.25.254.104

 

 

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

 

[root@westos-mail named]# dig -t mx westos.com

 

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

Subject: hello

hello world

.                                   ##用"."来结束录入内容并发送

EOT

[root@westos-mail ~]# mailq       ##查看邮件队列

Mail queue is empty

postqueue -f       ##重新处理邮件队列   

 

如果邮件发送不过去   在邮件接收端进行配置

1.postfix提供smtp协议用来投递邮件

默认端口是25

默认情况下邮件只在127.0.0.1上开启

2.配置

westos-mail主机上

vim /etc/postfix/main.cf

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

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

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

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

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

 

qq-mail主机上

vim /etc/postfix/main.cf

116 inet_interfaces = all

83 mydomain = qq.com

76 myhostname = qq-mail.qq.com

99 myorigin = qq.com

164 mydestination = $myhostname, $mydomain, localhost,

配置完成后,分别重启服务,关闭火墙

systemctl restart postfix.service

systemctl stop firewalld

 

 

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

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

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

[root@qq-mail ~]# mail

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

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

>N  1 root                  Sat May 20 03:14  21/733   "hello"

&

Message  1:

From root@westos.com  Sat May 20 03:14:06 2017

Return-Path: <root@westos.com>

X-Original-To: root@qq.com

Delivered-To: root@qq.com

Date: Sat, 20 May 2017 03:14:05 -0400

To: root@qq.com

Subject: hello

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

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

From: root@westos.com (root)

Status: R

 

hello world

 

New mail has arrived.

Loaded 1 new message

 N  2 root                  Sat May 20 03:17  21/741   "hello"

&

Message  2:

From root@westos.com  Sat May 20 03:17:56 2017

Return-Path: <root@westos.com>

X-Original-To: root@qq.com

Delivered-To: root@qq.com

Date: Sat, 20 May 2017 03:17:54 -0400

To: root@qq.com

Subject: hello

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

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

From: root@westos.com (root)

Status: R

 

i come from youdian

 

& ^Z

[1]+  Stopped                 mail

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

 

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

admin:          root

moreuser:       :include:/etc/postfix/moreuser

 

别名: 真名 ##邮件别名

别名: :include:filename ##邮件群发

 

[root@qq-mail ~]# vim filename

root

student

 

 

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

测试

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

Subject: yeyeye

yeyeye

.

EOT

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

Subject: hohou

hohou

.

EOT

[root@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 2 new

    1 root                  Wed May 24 13:22  22/731   "ooo"

>N  2 root                  Wed May 24 13:41  21/728   "yeyeye"

 N  3 root                  Wed May 24 13:41  21/730   "hohou"

&

 

 

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

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

"/var/mail/root": 6 messages 1 new 6 unread

 U  1 root                  Sat May 20 03:14  22/743   "hello"

 U  2 root                  Sat May 20 03:17  22/751   "hello"

 U  3 root                  Sat May 20 03:19  22/737   "hello gay"

 U  4 root                  Sat May 20 03:20  27/772   "hello boy"

 U  5 root                  Sat May 20 03:21  22/736   "hello"

>N  6 root                  Sat May 20 04:22  24/860   "ooo"

& ^Z

 

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

Subject: piu

piupiu

.

EOT

[root@westos-mail ~]# mailq

Mail queue is empty

 

 

 

 

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

 

[root@foundation57 ~]# telnet 172.25.254.157

Trying 172.25.254.157...

telnet: connect to address 172.25.254.157: Connection refused

[root@foundation57 ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

ehlo hello

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

250 2.1.0 Ok

rcpt to:root@qq.com

250 2.1.5 Ok

data

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

.

250 2.0.0 Ok: queued as D8B5D24664F

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

 

 

[root@qq-mail ~]# mail

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

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

    1 root                  Wed May 24 13:22  22/731   "ooo"

 U  2 root                  Wed May 24 13:41  22/738   "yeyeye"

 U  3 root                  Wed May 24 13:41  22/740   "hohou"

>N  4 root@westos.com       Wed May 24 13:48  11/477   

& 4

Message  4:

From root@westos.com  Wed May 24 13:48:27 2017

Return-Path: <root@westos.com>

X-Original-To: root@qq.com

Delivered-To: root@qq.com

Status: R

 

&

 

 

 

##########限制用户发送##########

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

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

student@westos.com  REJECT

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

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

[root@westos-mail postfix]# ls             ##生成sender.db文件

access     generic        main.cf    moreuser   sender     transport

canonical  header_checks  master.cf  relocated  sender.db  virtual

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

 

测试:

 

[root@foundation57 ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

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 <student@westos.com>: Sender address rejected: Access denied

 

 

 

###########限制用户接受#########

[root@westos-mail postfix]# useradd westos

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

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

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

westos@westos.com REJECT

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

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

 

 

 

测试

 

 

[root@foundation57 ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

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>

hhh

.

250 2.0.0 Ok: queued as 7D9F924664F

quit

221 2.0.0 Bye

Connection closed by foreign host.

[root@foundation57 ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

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

 

 

#########出站地址伪装#########

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

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

   真实名字              虚拟名字

westos@westos.com     hello@sb.com

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

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

 

 

测试

 

发送邮件

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

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

Subject: mamama

.

EOT

Null message body; hope that's ok

[westos@westos-mail ~]$ postqueue -f

[westos@westos-mail ~]$ mailq

Mail queue is empt

接收邮件

[root@qq-mail ~]# mail

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

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

    1 root                  Wed May 24 13:22  22/731   "ooo"

 U  2 root                  Wed May 24 13:41  22/738   "yeyeye"

 U  3 root                  Wed May 24 13:41  22/740   "hohou"

    4 root@westos.com       Wed May 24 13:48  12/488   

>N  5 hello@sb.com          Wed May 24 18:49  21/709   "mama"

&

 

 

 

############入站地址伪装############

 

DNS记录解析

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

 

zone "sb.com" IN {

        type master;

        file "sb.com.zone";

        allow-update { none; };

};

 

[root@westos-mail ~]# 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 sb.com.zone

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

 

$TTL 1D

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

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.sb.com.

dns             A       172.25.254.157

sb.com.         MX 1    172.25.254.157.

 

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

 

测试DNS解析是否完成

[root@qq-mail ~]# dig -t mx sb.com

 

 

#########入站地址转换##########

[root@westos-mail ~]# useradd hello

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

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

   虚拟名字           真实名字

 hello@sb.com    westos@westos.com

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

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

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

Last login: Sat May 20 22:41:58 EDT 2017 on pts/0

 

 

测试

 

回复邮件

[root@qq-mail ~]# mail hello@sb.com

Subject: houhou

.

EOT

Null message body; hope that's ok

[root@qq-mail ~]# postqueue -f

[root@qq-mail ~]# mailq

Mail queue is empty

 

邮件接收

[westos@westos-mail ~]$ mail

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

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

>N  1 root                  Wed May 24 18:57  21/715   "houhou"

& 1

Message  1:

From root@qq.com  Wed May 24 18:57:41 2017

Return-Path: <root@qq.com>

X-Original-To: hello@sb.com

Delivered-To: westos@westos.com

Date: Wed, 24 May 2017 18:57:40 -0400

To: hello@sb.com

Subject: houhou

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

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

From: root@qq.com (root)

Status: R

 

 

&

 

 

 

##############dovecot###############

 

1.

dovecot  用来提供收件协议

pop3       110

imap       143

imaps      993

pop3s      995

 

 

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

 

2.

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

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

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

 

 24 protocols = imap pop3 lmtp

 48 login_trusted_networks = 0.0.0.0/0

 49 disable_plaintext_auth = no

 

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

 

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

 

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

[root@westos-mail ~]# passwd westos

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

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

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

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

 

测试

 

[root@foundation4 ~]# yum install mutt -y

[root@foundation4 ~]# mutt -f pop://westos@172.25.254.104

1 kept, 0 deleted.

 

 

 

############postfix+mariadb#############

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

[root@westos-mail ~]# yum reinstall postfix.x86_64 -y

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

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

[root@westos-mail ~]# yum install httpd php php-mysql mariadb-server -y

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

[root@westos-mail ~]# vim /etc/my.cnf

skip-networking=1

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

[root@westos-mail ~]# systemctl restart mariadb       

[root@westos-mail ~]# mysql_secure_installation

[root@westos-mail ~]# cd /var/www/html

[root@westos-mail html]# ls

[root@westos-mail html]# cd

下载phpMyAdmin-3.4.0-all-languages.tar.bz2安装包

[root@westos-mail html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2  ##解压

[root@westos-mail html]# rm -fr *.bz2

[root@westos-mail html]# ls

phpMyAdmin-3.4.0-all-languages

[root@westos-mail html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin

[root@westos-mail html]# ls

myadmin

[root@westos-mail html]# cd myadmin/

[root@westos-mail myadmin]# ls

browse_foreigners.php     main.php                server_status.php

bs_disp_as_mime_type.php  navigation.php          server_synchronize.php

bs_play_media.php         phpdoctor.ini           server_variables.php

ChangeLog                 phpinfo.php             setup

changelog.php             phpmyadmin.css.php      show_config_errors.php

chk_rel.php               pmd                     sql.php

config.sample.inc.php     pmd_common.php          tbl_addfield.php

contrib                   pmd_display_field.php   tbl_alter.php

CREDITS                   pmd_general.php         tbl_change.php

db_create.php             pmd_help.php            tbl_chart.php

db_datadict.php           pmd_pdf.php             tbl_create.php

db_export.php             pmd_relation_new.php    tbl_export.php

db_import.php             pmd_relation_upd.php    tbl_get_field.php

db_operations.php         pmd_save_pos.php        tbl_import.php

db_printview.php          prefs_forms.php         tbl_indexes.php

db_qbe.php                prefs_manage.php        tbl_move_copy.php

db_search.php             print.css               tbl_operations.php

db_sql.php                querywindow.php         tbl_printview.php

db_structure.php          README                  tbl_relation.php

db_tracking.php           README.VENDOR           tbl_replace.php

docs.css                  RELEASE-DATE-3.4.0      tbl_row_action.php

Documentation.html        robots.txt              tbl_select.php

Documentation.txt         schema_edit.php         tbl_sql.php

enum_editor.php           schema_export.php       tbl_structure.php

export.php                scripts                 tbl_tracking.php

favicon.ico               server_binlog.php       themes

import.php                server_collations.php   themes.php

import_status.php         server_databases.php    TODO

index.php                 server_engines.php      transformation_overview.php

INSTALL                   server_export.php       transformation_wrapper.php

js                        server_import.php       url.php

libraries                 server_privileges.php   user_password.php

LICENSE                   server_processlist.php  view_create.php

license.php               server_replication.php  view_operations.php

locale                    server_sql.php          webapp.php

[root@westos-mail myadmin]# cp config.sample.inc.php config.inc.php

[root@westos-mail myadmin]# vim config.inc.php

[root@westos-mail myadmin]# systemctl start httpd

 

 [root@westos-mail myadmin]# mysql -uroot -pwestos

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 51

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> create user postuser@localhost identified by 'postuser';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> grants select,update,insert on email.* to postuser@localhost;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'grants select,update,insert on email.* to postuser@localhost' at line 1

MariaDB [(none)]> grant select,update,insert on email.* to postuser@localhost;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> quit

Bye

[root@westos-mail myadmin]# mysql -upostuser -ppostuser

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 52

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> select * from email.emailuser;

+---------------+----------+----------+---------------------+

| username      | password | domain   | maidir              |

+---------------+----------+----------+---------------------+

| haha@haha.com | haha     | haha.com | /mnt/haha.com/haha/ |

+---------------+----------+----------+---------------------+

1 row in set (0.00 sec)

 

MariaDB [(none)]> quit

Bye

[root@westos-mail myadmin]# cd

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

hosts = localhost   ##用户名称查询

user = postuser      ##数据库所在主机

password = postuser   ##登陆数据库的用户

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

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

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

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

 

[root@westos-mail ~]# vim /etc/postfix/mailbox.cf  ##用户邮箱地址查询

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = maildir

where_field = username

 

[root@westos-mail ~]# vim /etc/postfix/maildomain.cf  ##用户域名查询

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = domain

where_field = domain

 

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

haha@haha.com

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

haha.com

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

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

/mnt/haha.com/haha/

      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值