电子邮件服务的配置与应用

Edit on Github

测试环境

VirtualBox中的Arch和主机XP,其中arch中配置有DNS、postfix、imapd,有关DNS配置见前面日志

软件介绍

  • Arch中,postfix提供SMTP协议服务,imapd提供imap/pop服务
  • XP中,foxmail提供邮件收发

网络环境

Arch: IP 为192.168.0.98

Postfix的配置

配置文件为 /etc/postfix/main.cfg ,通过postconf -n得到,只要手动配置几项就好了,不配置的都按默认。

alias_database = $alias_map
alias_maps = hash:/etc/postfix/aliases
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = all
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/man
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain  # 服务范围
mydomain = maxint.org  # 域名配置
myhostname = mail.maxint.org  # 主机名
myorigin = $mydomain  # 后面的部分,与域名同比较好,当然与主机名同也行
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
relay_domains = $mydestination  # 邮件转发范围
sample_directory = /etc/postfix/sample
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)  # 命令行登录时的提示信息
smtpd_client_restrictions = permit_sasl_authenticated  
# 禁止未经过认证的客户端向postfix发起SMTP连接
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
# 对客户端发来的邮件进行过滤
smtpd_sasl_auth_enable = yes
# 启用sasl认证,对阻止广告和垃圾信息有一定作用,现在对作用实现原理还不清楚
smtpd_sasl_local_domain = ''
smtpd_sasl_security_options = noanonymous
# 禁止匿名登录方式
unknown_local_recipient_reject_code = 550

IMAPD 服务的启动

imapd的启动比较特殊,它是通过xinetd来启动的,要配置下xinetd才能实现效果。过程很简单明了,只要修改/etc/xinetd.d/目录下的对应文件imap、ipop2、ipop3是行了。

service imap2
{
  socket_type  = stream
  wait  = no
  user  = root
  server  = /usr/sbin/imapd
  log_on_success += HOST DURATION
  log_on_failure += HOST
  disable  =no本来是yes }

测试方法

在主机XP用foxmail收发,账号就是Arch上的用户账号,如 root@maxint.org,maxint@maxint.org。

命令行下的测试

XP下

telnet mail.maxint.org 25

再用foxmail收取

与外部的邮件收发测试

[root@arch1 ~]# telnet localhost 25 Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 mail.maxint.org ESMTP Postfix (2.4.6)
mail from:maxint@maxint.org
250 2.1.0 Ok
rcpt to:maxint@zju.edu.cn
250 2.1.5 Ok
data
354 End data with<CR><LF>.<CR><LF>mail from maxint.org
.
250 2.0.0 Ok: queued as 30950FBEC
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@arch1 ~]# tail /var/log/mail.log May 2 17:41:29 arch1 postfix/smtpd[3188]: connect from localhost.localdomain[127.0.0.1]
May 2 17:41:35 arch1 postfix/smtpd[3188]: disconnect from localhost.localdomain[127.0.0.1]
May 2 17:42:06 arch1 postfix/smtpd[3188]: warning: SASL authentication failure: OTP: auxprop backend can't store properties
May 2 17:42:06 arch1 postfix/smtpd[3188]: connect from localhost.localdomain[127.0.0.1]
May 2 17:42:43 arch1 postfix/smtpd[3188]: 30950FBEC: client=localhost.localdomain[127.0.0.1]
May 2 17:43:00 arch1 postfix/cleanup[3194]: 30950FBEC: message-id=<20080502174243.30950FBEC@mail.maxint.org>May 2 17:43:00 arch1 postfix/qmgr[3136]: 30950FBEC: from=<maxint@maxint.org>, size=373, nrcpt=1 (queue active)
May 2 17:43:01 arch1 postfix/smtp[3195]: 30950FBEC: to=<maxint@zju.edu.cn>, relay=zjuem.zju.edu.cn[10.10.8.55]:25, delay=43, delays=41/0.02/0.28/0.81, dsn=2.0.0, status=sent (250 OK:has queued)
May 2 17:43:01 arch1 postfix/qmgr[3136]: 30950FBEC: removed
May 2 17:43:06 arch1 postfix/smtpd[3188]: disconnect from localhost.localdomain[127.0.0.1]

WebMail的安装

我选择简洁实用的小松鼠网页电子邮件系统(squirrelmail),具体安装与配置就不记录了,详情参看安装目录下的INSTALL和README。要注意的是存放数据的data和attach文件夹,httpd用户可写的权限,httpd用户是哪个,可由httpd.conf文件指定,如我指定的是:

User nobody
Group nobody

data和attach文件夹的位置由,可以通过运行 path/to/squirrqlmail/config/conf.pl 脚本配置,值得一提的是squirrelmail还附带了很多小插件,可以极大地丰富WebMail的功能,更多插件可以到官方下载,而这一切都是FREE的!!