Postfix配置多域名
1.查找用户和组
#grep postfix /etc/group
#grep postfix /etc/passwd
安装postfix
#yum -y install postfix
2.先备份main.cf
[root@calpsv04 ~]# cd /etc/postfix
[root@calpsv04 postfix]# cp main.cf main.cf.bak
3.编辑main.cf
myhostname = mail.1a-CentOSserver.com
mydomain = 1a-centosserver.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.13.0/24, 127.0.0.0/8
relay_domains = $mydestination
home_mailbox = Maildir/
mydomain: mydomain参数是指email服务器的域名,请确保为正式域名(如centos.bz)
myhostname: myhostname参数是指系统的主机名称(如我的服务器主机名称是mail.centos.bz)
myorigin: myorigin参数指定本地发送邮件中来源和传递显示的域名。在我们的例子中,mydomain是centos.bz,也是我的域名。
对于下面的一行,我们的邮件地址是[email protected]而不是[email protected]。
myorigin = $mydomain
mynetworks: mynetworks参数指定受信任SMTP的列表,具体的说,受信任的SMTP客户端允许通过
Postfix传递邮件。
mydestination: mydestination参数指定哪些邮件地址允许在本地发送邮件。这是一组被信任的允许通过服务器发送或传递邮件的IP地址。用户试图通过发送从此处未列出的IP地址的原始服务器的邮件将被拒绝。 inet_interfaces: inet_interfaces参数设置网络接口以便Postfix能接收到邮件。
relay_domains: 该参数是系统传递邮件的目的域名列表。默认为mydestination,如果留空,我们保证了我们的邮件服务器不对不信任的网络开放。
home_mailbox: 该参数设置邮箱路径与用户目录有关,也可以指定要使用的邮箱风格。
4.开放SMTP的25端口
#iptables -A INPUT -p tcp --dport 25 -j ACCEPT
#service iptables save
5.通过telnet测试发送邮件
如果telnet没有,用#yum install telnet安装
[root@calpsv04 sysconfig]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 mail.apmro.com.sg 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 <CR><LF>.<CR><LF>
FROM:[email protected]
Subject:test message
test body
.
250 2.0.0 Ok: queued as 11F9340372
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@calpsv04 sysconfig]#
成功收到test邮件
5.安装Cyrus
#yum install cyrus*
安装完成之后,修改/etc/postfix/main.cf
local_recipient_maps = //209行,把前面的注释拿掉。 local_recipient_maps设置成empty意思就是
# To turn off local recipient checking in the SMTP server, specify
# local_recipient_maps = (i.e. empty).
smtpd_banner = $myhostname ESMTP unknow //568行,把前面的注释拿掉,然后把$mail_name ($mail_version)改成unknow
mailbox_transport=lmtp:unix:/var/lib/imap/socket/lmtp //设置连接cyrus-imapd的路径
//在main.cf文件的底部加上以下内容
smtpd_sasl_auth_enable = yes //使用SMTP认证
broken_sasl_auth_clients = yes //让不支持RFC2554的smtpclient也可以跟postfix做交互。
smtpd_sasl_local_domain = $myhostname // 指定SMTP认证的本地域名
smtpd_sasl_security_options = noanonymous //取消匿名登陆方式
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设定邮件中有关收件人部分的限制
smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设置允许范围
message_size_limit = 15728640 //邮件大小
6.编辑/etc/sasl2/smtpd.conf
[root@calpsv04 sasl2]# vi smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
添加下面两行
log_level: 3
saslauthd_path: /var/run/saslauthd/mux
7.启动服务
[root@calpsv04 etc]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@calpsv04 etc]# service saslauthd start
Starting saslauthd: [ OK ]
[root@calpsv04 etc]# service cyrus-imapd start
Importing cyrus-imapd databases: [ OK ]
Starting cyrus-imapd: [ OK ]
8.安装cyrus之后会自动创建一个cyrus系统用户,
#passwd cyrus更改这个用户的密码
9.验证sasl-authd,如果现实OK“success”说明正常。
[root@calpsv04 etc]# testsaslauthd -u cyrus -p '密码必须用单引号括起来'
0: OK "Success."
10.用cyrus 创建邮件账户
[root@calpsv04 etc]# id cyrus
uid=76(cyrus) gid=12(mail) groups=12(mail),76(saslauth)
cyrus-imapd服务的配置文件有以下3个。
/etc/sysconfig/cyrus-imapd:用于启动cyrus-imapd服务的配置文件。
/etc/cyrus.conf:是cyrus-imapd服务的主要配置文件,其中包含该服务中各个组件(IMAP、POP3、sieve和NNTP等)的设置参数。
/etc/imapd.conf:是cyrus-imapd服务中的IMAP服务的配置文件。
通过#telnet localhost 110测试pop3
在/etc/imap.conf中添加:
[crazywill@localhost crazywill]$ telnet pop.163.com 110 #telnet登录110端口
Trying 202.108.5.104...
Connected to pop.163.com.
Escape character is '^]'.
+OK Welcome to coremail Mail Pop3 Server (163com[20050206])
USER [email protected] # 用户名不需要base64编码
+OK core mail
PASS mypassword # 登录密码
+OK 254 message(s) [27676669 byte(s)]
STAT # 查看邮箱状态
+OK 254 27676669
LIST # 邮件列表
+OK 254 27676669
1 2468
2 21945
3 33136
4 2071
5 3364
6 18906
7 3136
8 24764
.................
TOP 254 0 # 查看指定邮件的邮件头,0表示查看整个邮件头,其它正整数表示限制返回多少行。
+OK core mail
Received: from smtp.63.com (unknown [58.252.70.158])
by smtp5 (Coremail) with SMTP id wKjREDrA9gIfFqlEjCnRAg==.29062S4;
Mon, 03 Jul 2006 21:07:18 +0800 (CST)
TO: [email protected]
FROM : [email protected] # 这里即前面发信时伪造的一个假发送人信息,平时正常操作只显示这个。
SUBJECT: test by telnet/smtp # 邮件主题
Message-Id: <44A91687.0E6F6C.07562>
Date: Mon, 3 Jul 2006 21:07:19 +0800 (CST)
Sender: [email protected] # 这里是真正的发送人,不可伪造。
.
RETR 254 # 获取指定邮件
+OK 354 octets
Received: from smtp.63.com (unknown [58.252.70.158])
by smtp5 (Coremail) with SMTP id wKjREDrA9gIfFqlEjCnRAg==.29062S4;
Mon, 03 Jul 2006 21:07:18 +0800 (CST)
TO: [email protected]
FROM : [email protected]
SUBJECT: test by telnet/smtp
Message-Id: <44A91687.0E6F6C.07562>
Date: Mon, 3 Jul 2006 21:07:19 +0800 (CST)
Sender: [email protected]
test, just a test.
.
DELE 254 # 删除第254封邮件
+OK core mail
STAT # 查看邮箱状态
+OK 253 27676315
QUIT # 退出
+OK core mail
Connection closed by foreign host.
[crazywill@localhost crazywill]$
cryadm
用“cyradm”可以创建、删除、限制和控制邮箱(详细可看帮助)。可用“cyradm ”命令启动,提示符将变成“>”。你可以用“help”命令,将会出现如下信息:
createmailbox, cm create a mailbox
deleteaclmailbox, dam delete an ACL on a mailbox
deletemailbox, dm delete a mailbox
help get help on commands
listaclmailbox, lam list the ACL on a mailbox
listmailbox, lm list mailboxes
listquota, lq list quota on root
listquotaroot, lqr, lqm list quota roots on mailbox
quit exit program
renamemailbox, renm rename a mailbox
setaclmailbox, sam set an ACL on a mailbox
setquota, sq set quota limits
注意:如果你的系统中,Kerberos v4 没有在运行,那你必须为用户设置密码。
根据邮箱的命名惯例,要求任何用户的第一级邮箱(收件箱)必须时“user.”格式的。可以用如下命令创建一个新邮箱:
createmailbox user.
比如为userid为"smith"的用户创建邮箱,可用如下命令:
createmailbox user.smith
用如下命令可限制空间:
setquota user.smith 10000。
[crazywill@localhost crazywill]$ telnet 192.168.0.1 143 #telnet登录IMAP协议的143端口
Trying 192.168.0.1...
Connected to xxxxxx
Escape character is '^]'.
* OK xxxxxxx System IMap Server Ready
A01 LOGIN abc 123 #用户登录
A01 OK LOGIN completed
A02 LIST "" * #列出所有信箱列表
* LIST () "/" "INBOX"
* LIST () "/" "Drafts"
* LIST () "/" "Sent Items"
* LIST () "/" "Trash"
* LIST () "/" "Junk E-mail"
* LIST () "/" "Virus Items"
* LIST () "/" "&XfJT0ZABkK5O9g-"
* LIST () "/" "&g0l6Pw-"
* LIST () "/" "&XfJT0ZABkK5O9g-/DailyReport"
* LIST () "/" "Jira"
* LIST () "/" "Admin"
* LIST () "/" "&V4NXPpCuTvY-"
A02 OK LIST Completed
A03 Select INBOX #选择收件箱
* 37 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] UIDs valid
* FLAGS (/Answered /Seen /Deleted /Draft)
* OK [PERMANENTFLAGS (/Answered /Seen /Deleted /Draft)] Limited
A03 OK [READ-WRITE] SELECT completed
A04 Search ALL #查询收件箱所有邮件
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
A04 OK SEARCH completed # 列出符合条件的邮件序号(ALL表示列出当前信箱INBOX中的所有邮件)
A05 Search new #查询收件箱所有新邮件
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* OK X-SEARCH in progress
* SEARCH
A05 OK SEARCH completed #找不到任何新邮件
A06 Fetch 5 full #获取第5封邮件的邮件头
* 5 FETCH (INTERNALDATE "27-Jun-2006 14:00:27 +0800" FLAGS (/Seen) ENVELOPE ("Tue, 27 Jun 2006 13:56:51 +0800" "test " (("xxxxxx" NIL "xxxx" "xxxxxx")) (("xxxxxx" NIL "xxxx" "xxxxxx")) (("xxxxxx" NIL "xxxx" "xxxxxx")) ((NIL NIL "xxx" "xxxxx")) NIL NIL NIL "<[email protected] >") BODY (("text" "plain" ("charset" "gb2312") NIL NIL "base64" 14 2) ("text" "html" ("charset" "gb2312") NIL NIL "base64" 420 7) "alternative") RFC822.SIZE 1396)
A06 OK Fetch completed
A07 Fetch 5 rfc822 #获取第5封邮件的完整内容
* 5 FETCH (RFC822 {1396}
[这里是邮件内容,太长,略...]
A07 OK Fetch completed
A08 Fetch 5 flags #查询第5封邮件的标志位
A08 OK Fetch completed
A09 Store 5 +flags.silent (/deleted) #设置标志位为删除
A09 OK STORE completed
A10 Expunge #永久删除当前邮箱INBOX中所有设置了/deleted标志的信件
A10 OK EXPUNGE completed
A11 noop # 空语句
A11 OK NOOP completed
A20 LOGOUT #退出
* BYE IMAP4rev1 Server logging out
A20 OK LOGOUT completed
Connection closed by foreign host.
[crazywill@localhost crazywill]$
======= 关于外网telnet不上postfix 25的问题。
postfix安装好之后,本地telnet 127.0.0.1 25是正常的。但是在另外一台机器上telnet ip 25的话,一直报no route use,也不是报connect refuse。外网更加连不上了,
一开始以为防火墙设置有问题,但是防火墙25,110,143端口都开放着,后来看到有些人用iptables -F清楚了所有规则的做法,结果死马当活马医,也就照搬执行了一下,结果外网也能telnet '公网ip' 25了。不知道为什么