1、安裝
sudo apt-get install msmtp
2、查看配置文件路徑
huyuke@huyuke:~$ msmtp –version
msmtp version 1.4.19
TLS/SSL library: GnuTLS
Authentication library: GNU SASL
Supported authentication methods:
plain cram-md5 digest-md5 gssapi external login ntlm
IDN support: enabled
NLS: enabled, LOCALEDIR is /usr/share/locale
Keyring support: none
System configuration file name: /etc/msmtprc
User configuration file name: /home/git/.msmtprc
Copyright (C) 2009 Martin Lambers and others.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
3、配置一下msmtp的配置文件
huyuke@huyuke:~$ sudo vim /etc/msmtprc
# Set default values for all following accounts.
defaults
logfile /home/huyuke/msmtp.log #需要新建該文件記錄日誌
# The SMTP server of the provider.
account huyuke
host SMTP服務器
from 用來發送郵件的email地址
auth login
user 郵件帳戶
password 郵件帳戶密碼
# Set a default account
account default : huyuke
測試一下發送郵件
huyuke@huyuke:~$ msmtp [email protected]
TEST by msmtp
ctrl+d #退出編輯併發送
huyuke@huyuke:~$ tail -f msmtp.log 看看有沒有成功。
然後再進入到上面的郵件中,看看信收到沒有
然後配置做個/usr/bin/msmtp到/usr/sbin/sendmail的符號鏈接也可以
4、應用舉例
在設置好配置文件後,就可以在命令行下用msmtp發送郵件
在shell下運行命令:msmtp -t #這裏用 -t 來指定收件人。由於msmtp要從標準輸入中讀取郵件,因此回車後,進入輸入方式,下面接着輸入:
to: [email protected] #設定收件人,以便讓 -t 參數生效
subject: test #設定主題
#空行
test smtp
ctrl+D結束