It also can relay mail from other machine/device if relay function is enabled.
SMTP 伺服器預設只可以允許本機送出郵件。
如果開啟轉發功能的話,就可以讓外部機器經由本機送出郵件。
OS: CentOS 5.3
作業系統: CentOS 5.3
Reference
http://apt.nc.hcc.edu.tw/web/student_server_centos/student_server_centos.html#smtp
Step 1. Install sendmail,m4 and sasl programs.
安裝 sendmail 與修改設定檔的 m4 程式,還有認證的 sasl 程式。
yum -y install sendmail sendmail-cf m4 cyrus-sasl
Step 2. add local host name in local-host-names file.
在local-host-names file加入本機名稱
vi
/etc/mail/local-host-names
your.machine.hostname
Step3. modify sendmail template configuration (not direct used by sendmail)
修改 sendmail 的設定檔 (並非 sendmail 直接使用的設定檔)
vi
/etc/mail/sendmail.mc
dnl TRUST_AUTH_MECH(`EXTERNAL 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')
=>
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
=> DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')
Step 4. transfer .mc to cf for sendmail
利用 m4 把設定檔轉成 sendmail 使用的的設定檔
m4
/etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Step 5. edit relay access configuration (not direct used by sendmail)
編輯哪台機器可以轉發 的權限 (並非 sendmail 直接使用的設定檔)
vi
/etc/mail/access
Connect:localhost.localdomain
RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:remote.machine.ip
RELAY
Step 6. transfer access database for sendmail
利用 makemap 把設定檔轉成 sendmail 使用的設定檔
makemap hash
/etc/mail/access < /etc/mail/access
Step 7. start sendmail and sasl service
重新執行 sendmail 和 sasl 服務
/etc/rc.d/init.d/saslauthd restart
/etc/rc.d/init.d/sendmail restart
/etc/rc.d/init.d/sendmail restart
p.s. you can enable sendmail and sasal on boot
設定開機執行 sendmail 與sasl
chkconfig saslauthd
on
chkconfig sendmail on
chkconfig sendmail on
Step 8. add firewall rule for allow specific IP to send mail from this machine.
加入防火牆規則以允許特定 IP 可以透過此台寄送郵件
vi
/etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -p tcp -m
tcp --dport 25 -j ACCEPT
Step 9. restart firewall
重新啟動防火牆
service iptables restart
p.s. test SMTP server from other machine
從別的機器測試是否可連接到本機 port 25
telnet your.smtp.ip
25
Trying your.smtp.ip...
Connected to 140.109.53.5 (140.109.53.5).
Escape character is '^]'.
220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8; Thu, 3 Jan 2013 14:55:16 +0800
=> Works
telnet your.smtp.ip
25Trying your.smtp.ip...
telnet: connect to address your.smtp.ip: No route to host
=> Something worong
telnet: connect to address your.smtp.ip: No route to host
=> Something worong
*. check mail queue
查看是否有未寄出的信
sendmail -bp
sendmail -bp
*. checking mail
查看 log
cat /var/log/maillog
No comments:
Post a Comment