歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux 使用SMTP代理發送郵件

Linux 使用SMTP代理發送郵件

日期:2017/2/28 13:56:10   编辑:Linux教程

對於想在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 [email protected] 登陸郵箱的賬號,如[email protected]

set smtp=smtp.XXX.com 郵箱的smtp服務器,如smtp.126.com

set [email protected] 郵箱的用戶名,比如[email protected]

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" [email protected]

根據網速、運營商、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="[email protected]" 發件箱地址

set envelope_from=yes


編輯 /root/.msmtprc添加如下代碼

account default

host smtp.126.com 所用郵箱的smtp地址

from [email protected] 發件箱地址

auth login 登錄,根據smtp支持的認證方式修改

user linuxidc 郵件賬號,不包括@後面的域名

password linuxidc 發件箱密碼

logfile /var/log/msmtp.log 日志文件路徑


service postfix restart

echo 'This is a test mail' | mutt -s 'Test' -a /tmp/test.txt [email protected]

Copyright © Linux教程網 All Rights Reserved