linux server postfix服务配置
postfix(MTA)
邮件系统角色
1、MUA(邮件用户代理) mail/mutt foxmail outlook web
2、MTA(邮件传输代理) exchange notes sendmail postfix qmail
3、MDA(邮件分发代理 )
邮件应用协议
1、SMTP,简单邮件传输协议,TCP 25端口,加密端口465,发邮件,一般工作在邮件服务器
2、POP3,第3版邮局协议,TCP 110端口,加密端口995接收邮件
3、IMAP4,第4版因特网消息访问协议,TCP 143端口,加密端口993
发)user01@sina.com.cn ---smtp---->(sina) ---smtp-----[google] {user02} ----pop3/imap4 (收)
MUA MTA MDA 【MX】
MUA
测试邮件发送:
本机发送:
mail:(mail-->MTA(localhost:25)-->root@localhost-->/var/spool/mail/root)
# echo "123" | mail -s "a test mail" root@localhost
# sendmail a@localhost
hello,a.
test mail from sendmail.
.
网络发送:
telnet:
telnet localhost 25 --访问本机的邮件服务器
ehlo localhost --通告邮件服务器
mail from:root@localhost --发件人
rcpt to:a@localhost --收件人
data --邮件body
Subject:A Test Mail --主题
fdafdafdsa
fdafdfdsa
fdafdas --邮件的内容
. --结束
Postfix逻辑结构图
说明:
1、椭圆形的图标表示postfix程序
2、黄底方形的代表postfix的投递目录
3、蓝底方形的代表在投递过程中postfix进程调用外部的文件
结论:
1、postfix采用模块化设计,流水线作业。
2、postfix可以通过两种方式来接收邮件,一个本地(sendmail),另一个网络(smtp)
3、有三个出口,分别是local,smtp,pipe
安装postfix
1.如果有sendmail,需要先停掉旧的MTA
# service sendmail stop
# chkconfig sendmail off
2.安装postfix
# yum -y install postfix
# rpm -ql postfix
/etc/pam.d/smtp.postfix --pam验证设置,默认情况下postfix使用系统验证
/etc/postfix --存放配置文件
/etc/postfix/access --smtp访问控制
/etc/postfix/main.cf --主配置文件,postfix基本所有的配置都在此
/etc/postfix/master.cf --核心配置文件,实现邮件程序的调度
/sbin/ --postfix管理员命令(root)
/usr/libexec/postfix --所有用户都能调用的命令
/var/spool/postfix --邮件投递切换目录
/etc/rc.d/init.d/postfix --启动脚本
实例:
postfix(MTA smtp)+dovecot(pop3/imap)+squirrelmail(webmail)+apache+php+bind
确认的DNS的配置(MX记录)/主机名,把邮件服务器的首选DNS指向正确的DNS服务器
# nslookup
> set type=mx
> baidu.com
Server: 192.168.0.39
Address: 192.168.0.39#53
baidu.com mail exchanger = 5 mail.baidu.com.
配置主机名:
# hostname mail.baidu.com
# vim /etc/sysconfig/network
HOSTNAME=mail.baidu.com
# vim /etc/hosts
192.168.0.16 mail.baidu.com baidu.com mail
# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
debug_peer_level = 2
home_mailbox = Maildir/ --邮箱的存储格式,mailbox只有一个文件存储邮件
html_directory = no
inet_interfaces = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $mydomain, localhost
mydomain = baidu.com
myhostname = mail.baidu.com
mynetworks = 192.168.0.0/24
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
sample_directory = /usr/share/doc/postfix-2.3.3/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
# service postfix restart
# chkconfig postfix on
# netstat -tnlp |grep :25 --postfix使用smtp协议
使用dovecot实现110/143收信
# yum -y install dovecot
# vim /etc/dovecot/conf.d/10-auth.conf --让dovecot支持明文验证
disable_plaintext_auth = no
(error -ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections. )
# service dovecot start
# chkconfig dovecot on
netstat -tlp|grep dove
tcp 0 0 *:imaps *:* LISTEN 21275/dovecot
tcp 0 0 *:pop3s *:* LISTEN 21275/dovecot
tcp 0 0 *:pop3 *:* LISTEN 21275/dovecot
tcp 0 0 *:imap *:* LISTEN 21275/dovecot
# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user mail_a --使用mail_a登录
+OK
pass 123 --密码
+OK Logged in.
list --列出新邮件列表
+OK 1 messages:
1 499
.
retr 1 --读取编号为1的那封邮件.
2、使用outlook或者foxmail图形客户端来收取邮件
+++++++++++++++++++++++++++++++++++++
测试:
本地发送 echo "hello a" | mail -s "a test mail from local" a@baidu.com
收信:1)$HOME/Maildir
2) telnet localhost 110 user a pass 1
网络发送
[root@mail new]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.baidu.com ESMTP Postfix
ehlo localhost
250-mail.baidu.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:a@baidu.com
250 2.1.0 Ok
rcpt to:b@baidu.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject: a test mail
hi b!....
.
250 2.0.0 Ok: queued as 513CD609B4
quit
221 2.0.0 Bye
Connection closed by foreign host.
收信
1)$HOME/Maildir
2) telnet localhost 110 user a pass 1
[root@mail new]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user b
+OK
pass 1
+OK Logged in.
list
+OK 1 messages:
1 432
.
retr 1
+OK 432 octets
Return-Path: <a@baidu.com>
X-Original-To: b@baidu.com
Delivered-To: b@baidu.com
Received: from localhost (localhost [127.0.0.1])
by mail.baidu.com (Postfix) with ESMTP id 513CD609B4
for <b@baidu.com>; Thu, 13 Jun 2013 14:16:05 +0800 (CST)
subject: a test mail
Message-Id: <20130613061622.513CD609B4@mail.baidu.com>
Date: Thu, 13 Jun 2013 14:16:05 +0800 (CST)
From: a@baidu.com
To: undisclosed-recipients:;
hi b!....