全功能邮件服务搭建文档
http://www.iyunv.com/thread-38180-1-2.html
Linux+possfix配置邮件发送
经常使用到的命令:find / -name‘’;
注意:端口25需要打开
一:概述
Postfix:linux服务器发送邮件的一种工具.
二:环境准备
1,先关掉其他的邮件发送工具
例如:sendmail所有的服务关闭
命令:# service sendmail stop
# chkconfig sendmail off
#rpm -qa| grep sendmail | xargs rpm –e
三:安装工具并进行工具配置(如果工具已经存在则自己选择是否重新安装)
1,postfix安装
(1)在线安装命令:yum install postfix
(2)配置postfix文件mail.cf
光标移至第75行,修改myhostname
myhostname = mail.XXX.XXXX.XXXX
光标移至第83行,修改mydomain
mydomain =XXX.XXXX.XXXX
光标移至第99行,修改myorigin
myorigin = $mydomain
光标移至第116行,修改inet_interfaces
inet_interfaces = all
光标移至第119行,修改inet_protocols
inet_protocols = ipv4
光标移至第164行,添加$mydomain
mydestination = $myhostname, localhost.$mydomain,localhost, $mydomain,XXX.XXXX.XXXX
最后一个参数为指定发给本地邮件的域名
添加如下配置
smtpd_sasl_auth_enable= yes
smtpd_recipient_restrictions=permit_sasl_authenticatedpermit_auth_destination reject
broken_sasl_auth_clients= yes
smtpd_sasl_security_options= noanonymous
(3)保存退出,执行命令使修改的配置文件生效
命令: postfix reload
2安装openssl
(1)在线安装命令
#yum install openssl openssl-devel
3安装cyrus-sasl 自己下载
(2)解压:# tar –xzvf cyrus-sasl-2.1.25.tar.gz
(3)进入解压目录进行编译,configure文件需要有执行权限,
#envCPPFLAGS="-I/usr/include/openssl"
./configure --prefix=/usr/include/sasl/
./configure --with-openssl=/usr --with-mysql=/usr \
--prefix=/usr \
--sysconfdir=/etc \
--with-dbpath=/etc/sasldb2 \
--with-saslauthd=/var/run/saslauthd--disable-anon \
--enable-login --enable-ntlm --disable-digest
标红字段目录要正确,然后整体执行,可以用find / -name ‘’查找
(4)编译完后进行安装
#make
#make install
4其他工具文件配置
(1) 配置SMTP认证的相关选项
一, smtpd.conf(选择性配置)
#vi /usr/lib/sasl2/smtpd.conf 打开文件进行编辑
pwcheck_method: saslauthd ← 找到此行,将“saslauthd”改为“auxprop”
(仍然需要使用pwcheck_method:saslauthd,否则会认证失败)
pwcheck_method: auxprop ← 不使用系统用户密码作为用户的SMTP认证密码
二, saslauthd
# vi /etc/sysconfig/saslauthd
MECH=pam ← 找到这一行,在前面加#
#MECH=pam ← 不使用pam机制
FLAGS= ← 找到此行,在等号后面添加“sasldb”
FLAGS=sasldb ← 定义认证方式为sasldb2
重启服务让配置生效service saslauthd start
三 密码配置
#saslpasswd2 -u xxx.xxxx.xxx -c root
Password: ← 在这里输入密码(和登录一样不会显示)
Again (for verification): ← 再次输入密码
四 权限配置
# chgrp -R postfix /etc/sasldb2 ← 将数据库归属改postfix,
# chmod –R 640 /etc/sasldb2 ← 将数据库属性改为640
五 添加DNS server.
因为在邮件发送过程中,需要把邮件地址的domain地址转化成IP地址,再去发送给对应的收件人)
#vim /etc/resolv.conf
添加如下行:
nameserver 8.8.8.8
nameserver 8.8.4.4
六 配置hosts映射
#vi /etc/hosts
增加:
xxx.xxx.xxx xxx.xxx.xxx
七 mail.rc(可选)
创建用户
#adduser service
#passwd service
#vi/etc/mail.rc
增加:
set from=service@xxx.xxx.xxx smtp=mail.xxx.xxx.xxx
set smtp-auth-user=service smtp-auth-password=xxxxxxxxx set smtp-auth=login
四 启动服务并检查已经配置的工具
# chkconfig saslauthdon ← 将SMTP-Auth设置为自启动
# chkconfig --list saslauthd ← 确认SMTP-Auth服务状态
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on6:off ← 确认2~5为on的状态就OK
# /etc/rc.d/init.d/saslauthd start ← 启动SMTP-Auth
Starting saslauthd: [ OK ]
# chkconfig postfix on ← 将Postfix设置为自启动
# chkconfig --list postfix ← 确认Postfix服务状态
postfix 0:off 1:off 2:on 3:on 4:on 5:on6:off ← 确认2~5为on的状态就OK
# /etc/rc.d/init.d/postfix start ← 启动Postfix
Starting postfix: [ OK ]
五 用命令行测试邮件的发送
1,发送命令
#mailx -v -s test xxxxx@xxxx.xxxx enter键
Test 发送内容
CTRL+D 执行发送
2日志查看
Postfix邮件的log位置是:/var/log/maillog
运行日志: tail –f maillog
(250 2.0.0 Ok: queued as7F8BA634B4_5C05013F)
六 邮件服务其他功能(可选)
1发送人使用别名
真实发送人(用户+@+域名)与别名之间的映射文件(这里使用的自带的文件映射方法)
在/etc/postfix/canonical文件(如果没有新建一个),添加映射关系,添加方式如下:
可以设置多个用户的映射关系,实现切换用户发送
真实发送人 别名
例如:
当使用service用户发送时可以
service@xxxx.xxx.xx XXX@XXX.XXX
当使用web用户发送
web@xxx.xxx.xxx XXX@XXX.XXX
service@xxx.xxx.xxx XXX@XXX.XXX
在/ext/postfix/main.cf映射文件的引入
canonical_maps = hash:/etc/postfix/canonical
刷新映射文件和postfix,是更改生效,命令如下:
postmap /etc/postfix/canonical
postfix reload