Sendmail+Openwebmail
1.1.软件安装sendmaills
yum install sendmail* perl-Compress-Zlib perl-suidperl perl-Text-Iconv –y
yum -y install sendmail-cf.i* sendmail-doc.i*
1.2. 配置sendmail服务:
- 配置系统服务
# 备份系统文件
cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc.bak
cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.bak
# 添加访问域名
echo “mgcrazy.com” >>/etc/mail/local-host-names
- 配置监听所有地址:
sed -i ‘s/Addr=127.0.0.1/Addr=0.0.0.0/g’ /etc/mail/sendmail.mc
- 配置用户认证:
SendMail运行过程是读取/etc/mail/sendmail.cf配置文件,但该文件配置比较复杂,所以一般是配置/etc/mail/sendmail.mc,然后通过以下命令生成sendmail.cf文件
(每次修改sendmail.mc后都必须通过使用该命令后再重启sendmail服务,否则配置不会生效)。 网管网bits
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
在/etc/mail/sendmail.mc文件对格式要求非常严格:
- 每句左边不能有空格
- 区分大小写
- 注释在最左边加dnl
- 每句必须以dnl结束
- 增加的语句,不能在最后一行
语句中的引号,如下图
修改vi /etc/mail/sendmail.mc 如下两行:
Dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN‘)dnl
Dnl define(`confAUTH_MECHANISMS‘, `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN‘)dnl修改成
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN‘)dnl
define(`confAUTH_MECHANISMS‘, `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN‘)dnl
即去掉首行的dnl 。这样sendmail配置完毕。
修改完后用M4命令生成mail配置文件 m4 sendmail.mc >sendmail.cf
1.3. 配置SMTP和POP3认证:
saslauthd服务作用:提供smtp验证
service saslauthd restart
安装dovecot服务(pop3),
yum install –y dovecot*
去掉/etc/dovecot/dovecot.conf如下行前面的#号即可:
protocols = imap pop3
修改/etc/dovecot/conf.d/10-mail.conf
修改邮箱位置,如果不修改的话,后面在发邮件的时候会提示跟mail_location相关的错误,取消注释
mail_location = mbox:~/mail:INBOX=/var/mail/%u
修改/etc/dovecot/conf.d/10-auth.conf
修改是否允许简单信息验证,如果不修改的话,后面发邮件会提示验证错误而不能通过验证,
Yes改成no
disable_plaintext_auth = no
修改/etc/dovecot/conf.d/10-ssl.conf
修改是否使用ssl验证,如果不修改的话,同样在发送邮件的时候会提示不能通过验证,去掉注释,改成no
ssl = no
1.4. sendmail配置完毕
邮箱用户的建立,可以用客户端收发邮件即正常
groupadd mailgroup
useradd -g mailgroup -s /sbin/nologin user1
passwd wugk 设置好密码即可。
service sendmail restart&&service dovecot restart &&service saslauthd restart
给用户所有组权限
chgrp mailgroup /var/mail/user1
1.5.添加中继
数据库文件 /etc/mail/access.db
Vi /etc/mail/access
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:10.204.0.0 RELAY
makemap hash access.db<access
1.6.配置openwebmail
Openwebmail是一个php页面文件,需要用httpd发布,要安装apache
- 安装openwebmail包
wgethttp://openwebmail.org/openwebmail/download/redhat/rpm/release/2.53/openwebmail-2.53-3.i386.rpm
wget http://openwebmail.org/openwebmail/download/redhat/rpm/release/2.53/openwebmail-data-2.53-3.i386.rpm
1、修改openwebmail配置如下:都是修改的内容:
[[email protected] ~]#vi /var/www/cgi-bin/openwebmail/etc/dbm.conf
dbm_ext .pag
dbmopen_ext none
dbmopen_haslock no
然后初始化 ./var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init 按Y即可
2、修改、vi /var/www/cgi-bin/openwebmail/etc/defaults/dbm.conf
dbm_ext .pag
dbmopen_ext none
dbmopen_haslock no
3、修改vi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
domainnames mgcrazy.com
default_language zh_CN.GB2312
default_iconset Cool3D.Chinese.Simplified
4、修改vi /var/www/cgi-bin/openwebmail/etc/default/openwebmail.conf
domainnames mgcrazy.com
smtpserver mail.mgcrazy.com
authpop3_server mail.mgcrazy.com
然后再执行/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init 按Y即可
5、apache修改配置文件
以下是apache配置段供参考:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName mail.mgcrazy.com
DocumentRoot /usr/local/apache-2.2.13/
ScriptAlias /cgi-bin/ "/usr/local/apache-2.2.13/cgi-bin/"
<Directory /usr/local/apache-2.2.13/>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/$ http://mail.mgcrazy.com/cgi-bin/openwebmail/openwebmail.pl [P,L,NC]
</VirtualHost>
配置完毕测试:你的做好DNS解析,遇到问题一点一滴解决,遇到的错误也很多,只有你真正去做了才会明白。
访问http://mail.mgcrazy.com 页面如下:
1.7.Sendmail故障
Starting Dovecot Imap: Error: socket()failed: Address family not supported by protocol
Error: service(pop3-login): listen(::, 110)failed: Address family not supported by protocol
这是因为系统不存在ipv6, 解决办法:
vi /etc/dovecot/dovecot.conf
把listen = * [::]改为listen = *
测试
[email protected] mail]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is ‘^]‘.
220
localhost.localdomain
ESMTP Sendmail 8.14.1/8.14.1; Wed, 2 Nov 2011 01:22:44 +0800
ehlo localhost //这是要输入的命令
250-localhost.localdomain
Hello
localhost.localdomain
[127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
//在AUTH后面有LOGIN就基本上可以在 OutlookExpress上认证了
250-DELIVERBY 250 HELP
quit //这是退出界面的意思
Nov 19 11:34:49 localhost dovecot:pop3-login: Disconnected (tried to use disabled plaintext auth):rip=10.204.0.171, lip=10.204.3.252
关闭plaintext=no