Linux 使用SMTP代理髮送郵件
對於想在Linux下面發送郵件,而且自己又沒有獨立的網域名稱主機,就不能向外部發送郵件。
因此可以用一下發放來解決這個問題,簡言之就是利用Linux當做一個郵箱的用戶端來登入已經存在的郵箱,比如126,163等等,用登陸的郵件來向外網發送郵件。
測試環境:
#uname -a
Linux 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
方法一:
yum install -y mailx
主要是修改/etc/mail.rc檔案
編輯 /etc/mail.rc檔案,添加以下內容:
set from=User@XX.com 登陸郵箱的帳號,如bkjia@126.com
set smtp=smtp.XXX.com 郵箱的smtp伺服器,如smtp.126.com
set smtp-auth-user=User@XX.com 郵箱的使用者名稱,比如bkjia@126.com
set smtp-auth-password=Password 郵件的密碼
set smtp-auth=login 認證方式:登陸
關閉系統的sendmail,postfix
#service sendmail stop
#service postfix stop
#chkconfig sendmail off
#chkconfig postfix off
發送測試郵件:
echo "hello" | mail -s "Title" bkjia@126.com
根據網速、電訊廠商、SMTP的情況不同,郵件發送將有延遲現象。
方法二: 運用 mutt 和 msmtp 代理髮送郵件
yum -y install mutt msmtp
編輯 /etc/Murrtc 添加如下代碼:
set sendmail="/usr/bin/msmtp" msmtp命令的絕對路徑
set use_from=yes
set realname="Test" 自訂顯示的寄件者
set from="bkjia@126.com" 寄件匣地址
set envelope_from=yes
編輯 /root/.msmtprc添加如下代碼
account default
host smtp.126.com 所用郵箱的smtp地址
from bkjia@126.com 寄件匣地址
auth login 登入,根據smtp支援的認證方式修改
user bkjia 郵件帳號,不包括@後面的網域名稱
password bkjia 寄件匣密碼
logfile /var/log/msmtp.log 記錄檔路徑
service postfix restart
echo 'This is a test mail' | mutt -s 'Test' -a /tmp/test.txt wantyi@126.com
本文永久更新連結地址: