CentOS 6、7下配置exim發郵件服務器
1. 配置epel源(exim包位於EPEL軟件源中)
CentOS7
# cat > /etc/yum.repos.d/epel.repo << EOF [epel] name=Extra Packages for Enterprise Linux 7 - \$basearch #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch failovermethod=priority enabled=1 gpgcheck=0 EOF
CentOS6
# cat > /etc/yum.repos.d/epel.repo << EOF [epel] name=Extra Packages for Enterprise Linux 6 - \$basearch #baseurl=http://download.fedoraproject.org/pub/epel/6/\$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=\$basearch failovermethod=priority enabled=1 gpgcheck=0 EOF
2. 禁止postfix
# service postfix stop
# chkconfig postfix off
3. 安裝exim
# yum -y install exim
4. 將exim設爲默認的MTA
# alternatives --set mta /usr/sbin/sendmail.exim
5. 修改exim配置文件
# vi /etc/exim/exim.conf #幾個參數 primary_hostname = mail.flying.com #查看源郵件時顯示Received: from mail.flying.com,如果不指定直接取操作系統的hostname domainlist local_domains = @ localhost : localhost.localdomain :mail.flying.com domainlist relay_to_domains = flying.com #允許通過改主機發送郵件的域名 hostlist relay_from_hosts = 127.0.0.1 : 192_32G : 10.168.0.0/16 :
#允許那些客戶端主機發送郵件,如本地使用這臺服務器發送郵件時,即需要添加本地出口ip地址(公網地址)
6. 測試
# yum -y install mailx
# date | mail -r [email protected] -s 'exim test' [email protected]
# tail -f /var/log/exim/main.log #exim日誌文件
ps:
如果不指定-r(發郵件地址),且你的主機名不是xxx.com,可能會報如下錯誤:
SMTP error from remote mail server after MAIL FROM:
錯誤是550 MI:IMF 發信人電子郵件地址不合規範
使用文件進行郵件發送:
date | mail -r [email protected] -s 'SN info TEXT ' [email protected] [email protected] < /root/sn.log mail命令的語法如下: Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ... [-- sendmail-options ...] mail [-iInNv] -f [name] mail [-iInNv] [-u user]
測試成功