Linux 使用SMTP代理髮送郵件

來源:互聯網
上載者:User

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

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.