OpenWRT 最大的賣點是擴展性,操作 OpenWRT 就像操作一台 Linux 機器差不多,在 OpenWRT 要發送電郵十分有用,例如可以監測伺服器運作,當發現問題後自動通知系統管理員。
由於很多網路供應商也會將 port 25 封鎖,所以這裡介紹的方法不是安裝完整的 MTA,而是安裝 mailsend 使用 Gmail 的服務發送電郵,這對於編寫 Shell Script 在 OpenWRT 也很適合。
首先安裝 mailsend 到 OpenWRT,先用 SSH 登入 OpenWRT, 然後執行以下指令:
# opkg update
# opkg install mailsend ca-certificates
# opkg install mailsend ca-certificates
安裝好 mailsend 後,可以用以下兩個方法透過 Gmail 發送電郵:
1 |
# mailsend -smtp smtp.gmail.com -port 465 -t to@email -f root@openwrt -sub 'nothing' -ssl -auth -user sender@gmail.com -pass "Secret_pass" -msg-body /tmp/resolv.conf |
1 |
# mailsend -smtp smtp.gmail.com -port 587 -t to@email -f root@openwrt -sub 'nothing2' -starttls -auth -user sender@gmail.com -pass "gmail_password" -msg-body /tmp/resolv.conf |
上面的 to@email 是收件方電郵; root@openwrt 是設定的回覆電郵地址; sender@gmail.com 是 gmail 帳號; gmail_password 是 Gmail 的密碼。以上例子會將檔案 /tmp/resolv.conf 的內容發出。