############################

#######   postfix #######

############################

·准备

wKiom1klrmnxQ78CAAAPfJjIwIA246.jpg

wKioL1klrmnwZDlOAAASiANdkik335.jpg

Mail_第1张图片

Mail_第2张图片

wKiom1klrtvwwpo5AAAVmcSbiwM640.jpg

Mail_第3张图片

Mail_第4张图片

Mail_第5张图片

wKiom1klr13jXKhlAAA0WnhYr_I532.jpg

Mail_第6张图片

wKiom1klr5zAeWpcAAAQ6w8Xch4031.jpg

Mail_第7张图片

Mail_第8张图片

Mail_第9张图片

wKiom1klsGWzlfa_AAAPj_QRczs032.jpg

Mail_第10张图片

Mail_第11张图片




1.

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

默认端口25

/var/log/maillog##服务日志

mail [email protected]

Subject: hello

hello world

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

mailq##查看邮件队列

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

 

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

 

2.

配置

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##接收邮件结尾字符的指定

 Mail_第12张图片

wKiom1kpe86wUImrAAAOnFKpHe8384.jpg

wKioL1kpe8_RtqUVAAAGg6Mx5-I134.jpg

wKiom1kpe8-iQ9t2AAAGCFl2sf4372.jpg

wKioL1kpe9DDJJ6aAAAI2_6AKbA827.jpg

wKioL1kpe9Chnld7AAAFkCyHzvU329.jpg



systemctl restart postfix.service

systemctl stop firewalld

wKioL1kpfBXAma7HAAANTmUC-DI227.jpg

 

Mail_第13张图片

Mail_第14张图片

 


 

3.邮件别名

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

别名:真名##邮件别名

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

 wKioL1kpgNnRlj2IAAAOkK-QyCY855.jpg

Mail_第15张图片

wKioL1kpgbyBcL9sAAARoAOjI4Q995.jpg

wKiom1kpgb3BkdIEAAAGl3q9NnA999.jpg



vim filename

user1

user2

 

postalias /etc/aliases

 wKioL1kpgdfTnnkIAAAP0_csM4U549.jpg

mail 别名

 

Mail_第16张图片

Mail_第17张图片

Mail_第18张图片

Mail_第19张图片


 

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

[kiosk@foundation0 Desktop]$ telnet 172.25.254.100 25

Trying 172.25.254.100...

Connected to 172.25.254.100.

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:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

250 2.1.5 Ok

data

354 End data with .

adsf

asdf

asdf

.

 wKioL1kpg9Cibma1AAAOyz_KASM243.jpg


5.邮件客户端的访问控制

#限制客户端

mta上

postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"

 

vim /etc/postfix/access

172.25.254.22REJECT

 

postmap /etc/postfix/access

 

systemctl restart postfix

 

测试

[root@foundation22 ~]# telnet 172.25.254.100 25

Trying 172.25.254.100...

Connected to 172.25.254.100.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

554 5.7.1 : Client host rejected: Access denied

 Mail_第20张图片

##限制用户发送

postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"

 

vim /etc/postfix/sender

[email protected]

 

postmap  /etc/postfix/sender

 

systemctl restart postfix

 

测试

[kiosk@foundation0 Desktop]$ telnet 172.25.254.100 25

Trying 172.25.254.100...

Connected to 172.25.254.100.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

554 5.7.1 : Sender address rejected: Access denied

 

 Mail_第21张图片

##限制用户接收

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

 

vim /etc/postfix/recip

[email protected]

 

postmap /etc/postfix/recip

 

systemctl restart postfix

 

测试

 

[kiosk@foundation0 Desktop]$ telnet 172.25.254.100 25

Trying 172.25.254.100...

Connected to 172.25.254.100.

Escape character is '^]'.

220 westos-mail.westos.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 .

adsf

adsf

asdf

.

250 2.0.0 Ok: queued as DE17D2461EA

qiut

502 5.5.2 Error: command not recognized

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

554 5.7.1 : Recipient address rejected: Access denied

 Mail_第22张图片

 

##出站地址伪装

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

 

vim /etc/postfix/generic

[email protected]@sb.com

 

postmap /etc/postfix/generic

 

systemctl restart postfix

 

测试

su - westos

mail [email protected]

 

##入战地址转换

dns mx 记录解析先做好

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

 

/etc/postfix/virtual

虚拟名字真实用户

[email protected]@westos.com

 

postmap /etc/postfix/virtual

 

systectl restart postfix

 

测试

mail [email protected]



####################################

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

####################################

1.

dovecot 用来提供收件协议

pop3   110

imap   143

pop3s  995

imaps  993

 

/etc/services   ###所有服务的所有端口

 

2.

yum install dovecot y  

 

 

3.

vim /etc/dovecot/dovecot.conf

24 protocols = imap pop3 lmtp

48 login_trusted_networks = 0.0.0.0/0

49 disable_plaintext_auth = no

 

vim /etc/dovecot/conf.d/10-mail.conf

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

 

systemctl restart dovecot

mkdir /etc/skel/mail/.imap -p           ###在用户骨架文件中建立所需目录及文件

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

 

useradd westos

passwd westos

测试

yum install mutt -y

mutt -f pop://[email protected]

 

 Mail_第23张图片

###################

thunderbrid

####################

thunderbird

收发邮件应用

 

 

 Mail_第24张图片

 

 

 

 

 

#########################

postfix + mariadb

#########################

准备工作

yum install httpd php php-mysql mariadb-server -y

config mariadb

mysql_secure_installation

create databs

create table

 

1.

vim /etc/postfix/mailuser.cf  ##用户名称查询

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

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

password = 123##登陆数据库的密码

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

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

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

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

 

 

vim /etc/postfix/maildomain.cf      ##用户域名查询

host = localhost

user = postuser

password = 123

dbname = email

table = emailuser

select_field = domain

where_field = domain

 

vim /etc/postfix/mailbox.cf     ##用户邮箱位置查询

host = localhost

user = postuser

password = 123

dbname = email

table = emailuser

select_field = maildir

where_field = username

 

postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf

[email protected]

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

mmm.com

postmap -q "[email protected]" mysql:/etc/postfix/mailbox.cf

/mnt/mmm.com/mmm

 

配置postfix

groupadd -g 666 vmail

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

 

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

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

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

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

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

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