Related Posts Plugin for WordPress, Blogger...

Lab1. 安裝 Dovecot 並設定 IMAPs 及 POP3s

#yum -y install dovecot
#make -C /etc/pki/tls/certs dovecot.pem
 Country Name (2 letter code) [GB]:TW
 State or Province Name (full name) [Berkshire]:Taiwan
 Locality Name (eg, city) [Newbury]:Taipei
 Organization Name (eg, company) [My Company Ltd]:Testing
 Organizational Unit Name (eg, section) []:直接 enter 即可
 Common Name (eg, your name or your server's hostname) []:server.example.com
 Email Address []:root@server.example.com    //完成後產生 /etc/pke/tls/certs/dovecot.pem
#vi /etc/dovecot.conf    //修改 devecot 設定檔
 protocols = imaps pop3s
 ssl_cert_file = /etc/pki/tls/certs/dovecot.pem
 ssl_key_file  = /etc/pki/tls/certs/dovecot.pem
#service dovecot start
#netstat -tnl
 tcp        0      0 :::993   (imaps)     :::*        LISTEN
 tcp        0      0 :::995   (pop3s)     :::*        LISTEN
#echo "test imaps" | mail -s "test imaps" weithenn
#mutt -f imaps://weithenn@server.example.com

若用 root 的話會失敗 (因為 Dovecot 預設擋住了),用 weithenn 的話會問你 password 輸入正確後即可看到此封測試 Mail。(請尊重 Weithenn 的辛勞!!)

Lab2 ~ 5. 安裝 Sendmail 可收信 (local-host-names)、可遞送 (Relay)、別名 (Aliases)

#yum –y install sendmail sendmail-cf
#netstat -tnl | grep :25      //預設聽 127.0.0.1
 tcp        0      0 127.0.0.1:25        0.0.0.0:*       LISTEN
#vi /etc/mail/sendmail.mc
 dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl    //開頭加上 dnl註解
#service sendmail restart
#netstat -tnl | grep :25      //修改後則聽 all interface
 tcp        0      0 0.0.0.0:25           0.0.0.0:*        LISTEN

Sendmail 用 local-host-names 來判斷郵件是否為本機郵件 (決定是否收下至 MailBox),若不是本機的信就會跑到 /var/spool/mqueue 並嘗試參考 /etc/mail/access 來轉送(Relay) 郵件出去。
#cat /etc/mail/local-host-names
 example.com
 station7.example.com
 mail.example.com

Sendmail 的 Relay 設定檔為 /etc/mail/access,例如 weithenn@server.example.com 寄給 chris@client.example.com 則在 server 上系統會發現 chris@client.example.com 不是本機郵件地址,所以會參考 /etc/mail/access 看郵件要轉送(Relay)給誰,所以 /etc/mail/access 要設定 client.example.com 且 client 要取消 SMTP 127.0.0.1 才可。
#vi /etc/mail/access
 Connect:192.168.0     RELAY     //表示幫區網轉送
#sendmail –q                   //重送郵件
#tail /var/log/maillog        //查 maillog
 stat=Deferred: client.example.com.: No route to host        //client firewall 沒開
 stat=Sent (nBQ5C3cg014254 Message accepted for delivery)    //寄成功

Sendmail 用 /etc/ aliases 來控制郵件的別名寄信。(請尊重 Weithenn 的辛勞!!)
#vi /etc/aliases
 hr: root,weithenn     //寄給 hr 就轉寄給 root 及 weithenn
#newaliases          //載入郵件別名
#echo "test" | mail -s "send to hr" hr@server.example.com
 Dec 26 08:30:35 server sendmail[6738]: nBQ0UY4s006738: from=<root@server.example.com>, size=344, class=0, nrcpts=1,
 msgid=<200912260030.nBQ0UX9G006736@server.example.com>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
 Dec 26 08:30:35 server sendmail[6736]: nBQ0UX9G006736: to=hr@server.example.com, ctladdr=root (0/0), delay=00:00:02,
 xdelay=00:00:01, mailer=relay, pri=30052, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0,  stat=Sent (nBQ0UY4s006738 Message accepted for delivery)
 Dec 26 08:30:35 server sendmail[6740]: nBQ0UY4s006738: to=weithenn, ctladdr=<root@server.example.com> (0/0), delay=00:00:00,
 xdelay=00:00:00, mailer=local, pri=60570, dsn=2.0.0, stat=Sent
 Dec 26 08:30:35 server sendmail[6740]: nBQ0UY4s006738: to=root, ctladdr=<root@server.example.com> (0/0),
 delay=00:00:00, xdelay=00:00:00, mailer=local, pri=60570, dsn=2.0.0, stat=Sent
文章標籤: