配置电子邮件传输+mariadb

1.首先配置两台虚拟机,

名字改为mailwestos.westos.com和maillinux.linux.com

ip分别设置为172.25.254.119和172.25.254.219

yum 源配置好。

2.配置dns

mailwestos主机上:yum install bind -y

[root@mailwestos ~]# vim /etc/named.conf

//      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; };

 

root@mailwestos ~]# cd /var/named

[root@mailwestos named]# ls

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

[root@mailwestos named]# vim /etc/named.rfc1912.zones

zone "westos.com" IN {

        type master;

        file "westos.com.zone";

        allow-update { none; };

};

 

zone "linux.com" IN {

        type master;

        file "linux.com.zone";

        allow-update { none; };

};

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

[root@mailwestos 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.119

westos.com.     MX 1    172.25.254.119.

                              

[root@mailwestos named]# cp -p westos.com.zone linux.com.zone //注意 -p

[root@mailwestos named]# vim linux.com.zone

$TTL 1D

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

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.linux.com.

dns             A       172.25.254.119

linux.com.      MX 1    172.25.254.219.

~                                             

[root@mailwestos named]# systemctl restart named

[root@mailwestos named]# vim /etc/resolv.conf

nameserver 172.25.254.119

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

2.发送邮件

直接mail root@linux.com时,会显示无法发送,linux(172.25.254.219)的25 端口没有打开

[root@mailwestos named]# netstat -antlpe | grep 25 //查看25端口是否开启

[root@mailwestos named]# rpm -qa | grep postfix //查看邮件服务协议是否安装

 

[root@mailwestos named]# vim /etc/postfix/main.cf

 76 myhostname = mailwestos.westos.com

83 mydomain = westos.com

99 myorigin = $mydomain

113 inet_interfaces = all

116 #inet_in164 mydestination = $myhostname, $mydomain, localhost

terfaces = localhost

164 mydestination = $myhostname, $mydomain, localhost

:wq

 

[root@mailwestos named]# systemctl restart postfix.service

[root@mailwestos named]# systemctl stop firewalld.service

 

linux(219)主机上做同样的配置改动

[root@mailwestos named]# systemctl stop firewalld.service

 

[root@mailwestos ~]# mail admin@linux.com

Subject: test

test

ddd

.

EOT

可以发送成功!

 

mail //查看接受的邮件

mailq //查看邮件是否发出

postqueue -f //邮件队列刷新

> /var/spool/mail/root //清空邮件队列

 

3.空壳邮件客户端

[root@maillinux ~]# vim /etc/aliases

在最后添加:admin:          root

 

[root@maillinux ~]# postmap /etc/aliases

[root@maillinux ~]# systemctl restart postfix.service

[root@maillinux ~]#postsuper -d 邮件编号(50CBD3260) //删除邮件

 

[root@mailwestos ~]#mail admin@linux.com

编辑邮件

 

[root@maillinux ~]#mail

linux主机查看邮件时可以发现实际上时发给了root用户

 

4.群发邮件

[root@mailwestos ~]# vim /etc/aliases

添加:more:           :include:/etc/postfix/users

[root@mailwestos ~]# vim /etc/postfix/users

root

student

[root@mailwestos ~]# postalias /etc/aliases

[root@mailwestos ~]# systemctl restart postfix.service

 

[root@maillinux ~]# mail more@westos.com

 

[root@mailwestos ~]# mail

[root@mailwestos ~]# mail -u student

 

5.企业级邮箱(虚拟邮箱)

1)

[root@maillinux ~]# vim /etc/postfix/virtual

添加:admin@qq.com root@linux.com

[root@maillinux ~]# postmap /etc/postfix/virtual

[root@maillinux ~]# ls /etc/postfix/

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport  virtual.db

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

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

[root@maillinux ~]# mail admin@qq.com

 

[root@mailwestos ~]# mail

可以在westos主机上查看到实际上发给了root@linux.com

 

[root@maillinux ~]# vim /etc/postfix/virtual

添加:@qq.com                 @linux.com    //虚拟的在前面,真实的在后面

[root@maillinux ~]# postmap /etc/postfix/virtual

[root@maillinux ~]# postconf -d | grep virtual //为了找到virtual_alias_maps =

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

[root@maillinux ~]# mail student@qq.com //任意用户

2)

自己主机可以接受虚拟域名的邮件:

[root@maillinux ~]# mail -u student

 Message  1:

From root@linux.com  Fri Mar 10 22:42:45 2017

Return-Path: <root@linux.com>

X-Original-To: student@qq.com

Delivered-To: student@linux.com

//可以看到实际上是发给了student@linux.com

 

3)

其他主机给虚拟域名(qq.com)发送邮件本来是不能发送的,配置以下服务就可以给他及虚拟域名发送邮件

[root@mailwestos ~]# mail root@qq.com

[root@mailwestos ~]# mailq

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

4F8AD17E863      452 Sat Mar 11 00:43:26  root@westos.com

(Host or domain name not found. Name service error for name=qq.com type=MX: Host not found, try again)

                                         root@qq.com

 

-- 0 Kbytes in 1 Request.

[root@mailwestos ~]# vim /etc/named.rfc1912.zones

添加:

zone "qq.com" IN {

        type master;

        file "qq.com.zone";

        allow-update { none; };

};

[root@mailwestos named]# cd /var/named

[root@mailwestos named]# ls

data     linux.com.zone  named.empty      named.loopback  westos.com.zone

dynamic  named.ca        named.localhost  slaves

[root@mailwestos named]# cp -p linux.com.zone qq.com.zone

[root@mailwestos named]# vim qq.com.zone

$TTL 1D

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

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.qq.com.

dns             A       172.25.254.119

qq.com.         MX 1    172.25.254.219.

~                                        

[root@mailwestos named]# systemctl restart named

[root@mailwestos named]# postqueue -f

[root@mailwestos named]# mailq

[root@mailwestos named]# systemctl restart postfix.service

配置之后就可以发送过去,完全实现了企业级邮箱,建立了虚拟邮箱

 

4)

实现以以虚拟域名为发送域名发送邮件,即就是在接受端看见发送者时虚拟域名:

 

root@maillinux ~]# postmap /etc/postfix/generic

在最后添加:@linux.com              @qq.com //真实的写在前面,虚拟的卸载后面

 postmap /etc/postfix/generic

[root@maillinux ~]# postconf -d| grep generic //为了找到smtp_generic_maps =

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

[root@maillinux ~]# systemctl restart postfix.service

效果:

[root@maillinux ~]# mail root@westos.com

Subject: hhhhhhhhhhhhhhhhhh

hhhhhhhhhhhhhh

.

EOT

 

 

[root@mailwestos named]# mail

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

"/var/spool/mail/root": 11 messages 4 unread

    1 root                  Fri Mar 10 21:43  23/752   "test"

    2 root                  Fri Mar 10 21:57  24/782   

    3 Mail Delivery System  Fri Mar 10 22:17  77/2509  "Undelivered Mail Retu"

    4 root                  Fri Mar 10 22:21  19/582   "oooooo"

    5 root                  Fri Mar 10 22:22  22/768   "pppppppppppp"

>U  6 root                  Fri Mar 10 22:25  19/574   "kkkkkkk"

    7 root                  Fri Mar 10 22:27  26/903   "hhhhhhhh"

 U  8 root                  Sat Mar 11 00:55  23/752   "jhkfahd"

 U  9 root                  Sat Mar 11 00:57  21/732   

   10 root                  Sat Mar 11 01:00  23/743   "adsf"

 U 11 root                  Sat Mar 11 01:01  22/761   "hhhhhhhhhhhhhhhhhh"

& 11

Message 11:

From root@qq.com  Sat Mar 11 01:01:51 2017

Return-Path: <root@qq.com>

X-Original-To: root@westos.com

Delivered-To: root@westos.com

Date: Sat, 11 Mar 2017 01:01:51 -0500

To: root@westos.com

Subject: hhhhhhhhhhhhhhhhhh

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

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

From: root@qq.com (root)

Status: RO

 

hhhhhhhhhhhhhh

 

& q

New mail has arrived.

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

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

 

6.在另一台主机上实现远程发送邮件和远程登陆邮件

60主机上:

[root@foundation60 Desktop]# yum install telnet

[root@foundation60 Desktop]# systemctl start telnet

[root@foundation60 Desktop]# telnet 172.25.254.119 25

Trying 172.25.254.119...

Connected to 172.25.254.119.

Escape character is '^]'.

220 mailwestos.westos.com ESMTP Postfix

ehlo hello //打招呼

250-mailwestos.westos.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:root@qq.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>

jijijijiji

jijijiji

jiiji

.

250 2.0.0 Ok: queued as A4C3B17E859

q

502 5.5.2 Error: command not recognized

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

[root@mailwestos ~]# mail

可以在客户端主机上查看到邮件 /

但是在远程主机未配置接受邮件的服务,还不能在远程主机上接受邮件,客户端配置如下配置如下:

 

7.远程接受邮件;

在客户端:

[root@mailwestos ~]# yum install dovecot

[root@mailwestos ~]# systemctl start dovecot

[root@mailwestos ~]# netstat -antlpe | grep dovecot

tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      0          207079     1486/dovecot        

tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      0          207055     1486/dovecot        

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      0          207053     1486/dovecot        

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      0          207077     1486/dovecot        

tcp6       0      0 :::993                  :::*                    LISTEN      0          207080     1486/dovecot        

tcp6       0      0 :::995                  :::*                    LISTEN      0          207056     1486/dovecot        

tcp6       0      0 :::110                  :::*                    LISTEN      0          207054     1486/dovecot        

tcp6       0      0 :::143                  :::*                    LISTEN      0          207078     1486/dovecot

        

[root@mailwestos ~]# vim /etc/dovecot/dovecot.conf

 

24 protocols = imap pop3 lmtp

48 login_trusted_networks = 0.0.0.0

49 disable_plaintext_auth = no

 

 

[root@mailwestos ~]# cd /etc/dovecot/conf.d/

[root@mailwestos conf.d]# ls

10-auth.conf       90-plugin.conf

10-director.conf   90-quota.conf

10-logging.conf    auth-checkpassword.conf.ext

10-mail.conf       auth-deny.conf.ext

10-master.conf     auth-dict.conf.ext

10-ssl.conf        auth-ldap.conf.ext

15-lda.conf        auth-master.conf.ext

15-mailboxes.conf  auth-passwdfile.conf.ext

20-imap.conf       auth-sql.conf.ext

20-lmtp.conf       auth-static.conf.ext

20-pop3.conf       auth-system.conf.ext

90-acl.conf        auth-vpopmail.conf.ext

[root@mailwestos conf.d]# vim 10-mail.conf

 

[root@mailwestos conf.d]# systemctl restart dovecot.service

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

 

[root@mailwestos conf.d]# su - student

[student@mailwestos ~]$ mkdir mail

[student@mailwestos ~]$ ls

mail

[student@mailwestos ~]$ cd mail

[student@mailwestos mail]$ mkdir /home/student/mail/.imap

[student@mailwestos mail]$ touch /home/student/mail/.imap/INBOX

 

在远程主机端:

[root@foundation60 Desktop]# yum install mutt -y

[root@foundation60 Desktop]# systemctl start mutt

[root@foundation60 Desktop]# mutt -f pop://student@172.25.254.119

远程登陆就可以查看到客户端主机上的邮件

 

8.配置开机就可以自动创建:/home/student/mail/.imap/INBOX

 

[root@mailwestos ~]# cd /etc/skel

[root@mailwestos skel]# ls

[root@mailwestos skel]# mkdir mail

[root@mailwestos skel]# cd mail

[root@mailwestos mail]# mkdir .imap

[root@mailwestos mail]# touch .imap/INBOX

[root@mailwestos mail]# ll -l /etc/skel/mail/.imap/INBOX

-rw-r--r--. 1 root root 0 Mar 11 01:57 /etc/skel/mail/.imap/INBOX

[root@mailwestos mail]# useradd test

[root@mailwestos mail]# passwd test

Changing password for user test.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

[root@mailwestos mail]# su - test

[test@mailwestos ~]$ ls

mail

 

9.posrfix客户端接受邮件+mysql的相关配置+php:

 

 

[test@mailwestos ~]$ yum install mariadb-server httpd php php-mysql

[root@mailwestos test]# systemctl start mariadb

[root@mailwestos test]# vim /etc/my.cnf

 

# instructions in http://fedoraproject.org/wiki/Systemd

skip-networking=1

[mysqld_safe]

 

[root@mailwestos test]# mysql_secure_installation

设置mysql客户端root用户登陆的密码

[root@mailwestos test]# systemctl restart mariadb.service

 

root@mailwestos test]# cd /var/www/html/

lftp 172.25.254.250:/pub/docs/software> get phpMyAdmin-3.4.0-all-languages.tar.bz2

4548030 bytes transferred  

[root@mailwestos html]# tar jxf  phpMyAdmin-3.4.0-all-languages.tar.bz2

[root@mailwestos html]# mv phpMyAdmin-3.4.0-all-languages/ mysqladmin

[root@mailwestos html]# cd mysqladmin/

[root@mailwestos mysqladmin]# ls

[root@mailwestos mysqladmin]# cp config.sample.inc.php config.inc.php

[root@mailwestos mysqladmin]# vim config.inc.php

 

17 $cfg['blowfish_secret'] = 'westos'; /* YOU MUST     FILL IN THIS FOR COOKIE AUTH! */

 

[root@mailwestos mysqladmin]# systemctl restart httpd

 

[root@mailwestos mysqladmin]# mysql -uroot -p

MariaDB [(none)]> CREATE USER postfix@localhost identified by 'postfix';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT INSERT.SELECT on email.* to postfix@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 'INSERT.SELECT on email.* to postfix@localhost' at line 1

MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit

 

[root@mailwestos mysqladmin]# mysql -upostfix -ppostfix

 

[root@mailwestos mysqladmin]# cd /etc/postfix

[root@mailwestos postfix]# ls

access     generic        main.cf    relocated  users

canonical  header_checks  master.cf  transport  virtual

[root@mailwestos postfix]# vim mysql-user.cf

 

hosts = localhost

user = postfix

password = postfix

dbname = email

table = mailusers

select_field = username

where_field = username

~                    

[root@mailwestos postfix]# cp mysql-user.cf mysql-domain.cf  

[root@mailwestos postfix]#vim mysql-domail.cf

 

hosts = localhost

user = postfix

password = postfix

dbname = email

table = mailusers

select_field = domain

where_field = domain

~                                                

[root@mailwestos postfix]# cp mysql-user.cf mysql-mailbox.cf

[root@mailwestos postfix]# vim mysql-mailbox.cf

 

hosts = localhost

user = postfix

password = postfix

dbname = email

table = mailusers

select_field = maildir

where_field = username

~                    

[root@mailwestos postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf

redhat.com

[root@mailwestos postfix]# postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-mailbox.cf

/var/spool/redhat.com/admin

[root@mailwestos postfix]#  postmap -q "admin@redhat.com" mysql:/etc/postfix/mysql-user.cf

admin@redhat.com

 

[root@mailwestos postfix]# groupadd -g 888 vmail

[root@mailwestos postfix]# useradd -u 888 -g 888 vmail

[root@mailwestos postfix]# cd /home/vmail/

[root@mailwestos vmail]# postconf -d | grep virtual

[root@mailwestos vmail]# postconf -e "virtual_mailbox_base = /home/vmail"

[root@mailwestos vmail]# postconf -e "virtual_gid_maps = static:888"

[root@mailwestos vmail]# postconf -e "virtual_uid_maps = static:888"

[root@mailwestos vmail]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"

[root@mailwestos vmail]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"

[root@mailwestos vmail]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf"

[root@mailwestos vmail]# vim /etc/postfix/main.cf

 

679 readme_directory = /usr/share/doc/postfix-2.10.    1/README_FILES

680 virtual_gid_maps = static:666

681 virtual_uid_maps = static:666

682 virtual_alias_maps = mysql:/etc/postfix/mysql-u    ser.cf

683 virtual_mailbox_domains = mysql:/etc/postfix/my    sql-domain.cf

684 virtual_mailbox_maps = mysql:/etc/postfix/mysql    -mailbox.cf

685 virtual_mailbox_base = /home/vmail

 

[root@mailwestos ~]# cd /home/vmail

[root@mailwestos vmail]# mail admin@redhat.com

Subject: jjjjjjjjjjjjjjjjj

dddddddddddd

ccccccccc

.

EOT

[root@mailwestos vmail]# mailq

Mail queue is empty

[root@mailwestos vmail]# cd /home/

[root@mailwestos home]# ls

student  vmail

[root@mailwestos home]# cd vmail/

[root@mailwestos vmail]# ls

redhat.com

[root@mailwestos vmail]# cd redhat.com/

[root@mailwestos redhat.com]# ls

admiin  admin

[root@mailwestos redhat.com]# rm -fr admiin/

[root@mailwestos redhat.com]# cd a

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

[root@mailwestos redhat.com]# cd admin/

[root@mailwestos admin]# ls

cur  new  tmp

[root@mailwestos admin]# cd new/

[root@mailwestos new]# ls

1489737773.Vfd01I136fc76M994432.mailwestos.westos.com

[root@mailwestos new]# cat 1489737773.Vfd01I136fc76M994432.mailwestos.westos.com

可以查看到传到mysql数据库中的邮件内容

 

 

10.thundebird的使用以及查看数据库收件箱:

 

[root@mailwestos ~]#systemctl stop firewalld.service

[root@mailwestos ~]#systemctl restart httpd

[root@mailwestos ~]#systemctl start mariadb

 

[root@mailwestos ~]# yum list dovecot

[root@mailwestos ~]#vim /etc/dovecot/dovecot.conf

 48 login_trusted_networks = 0.0.0.0/0 //允许访问网络地址

 49 disable_plaintext_auth = no //开始明文认证

 

[root@mailwestos vmail]# vim /etc/dovecot/conf.d/10-auth.conf

123 !include auth-sql.conf.ext

 

[root@mailwestos vmail]# ll /etc/dovecot/dovecot-sql.conf.ext

ls: cannot access /etc/dovecot/dovecot-sql.conf.ext: No such file or directory

[root@mailwestos vmail]# cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext

 

[root@mailwestos ~]# vim /etc/dovecot/dovecot-sql.conf.ext

 32 driver = mysql

71 connect = host=localhost dbname=email user=postfix password=postfix

78 default_pass_scheme = PLAIN

107 password_query = \

108   SELECT username, domain, password \

109   FROM mailusers WHERE username = '%u' AND domain = '%d'

125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM mailusers WHERE use    rname = '%u'

 

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

 30 mail_location = maildir:/home/vmail/%d/%n

 

在另一主机:

 

[root@foundation60 Desktop]# telnet 172.25.254.119 110

Trying 172.25.254.119...

Connected to 172.25.254.119.

Escape character is '^]'.

+OK [XCLIENT] Dovecot ready.

user admin@redhat.com

+OK

pass 234

+OK Logged in.

quit

同时在主机安装thunderbird并启动

验证成功后可以在thunderbird的收件箱上查看到postfix上的邮

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值