內容:
1,、msmtp工作模式
2,、命令行選項
3,、配置文件
4、配置文件示例
5,、應用舉例
msmtp是一個SMTP客戶端程序,,利用它可以在命令行下發(fā)郵件。
一,、工作模式:
msmtp共有三種工作模式:
Sendmail mode (default):
msmtp [選項...] [--] 收件人信箱...
msmtp [選項...] -t [--] [收件人信箱...]
Server information mode:
msmtp [option...] --serverinfo
Remote Message Queue Starting mode:
msmtp [option...] --rmqs=host|@domain|#queue
在默認模式(sendmail mode)下, msmtp從標準輸入讀入郵件,,然后送到SMTP服務器上轉發(fā)。
在server information mode下, msmtp顯示SMTP服務器的信息(如支持的認證方式,,郵件最大長度等),。
In Remote Message Queue Starting mode, msmtp sends a Remote Message
Queue Starting request for a host, domain, or queue to an SMTP server.
二、命令行選項:
命令行選項可覆蓋配置文件中的相同設置,。
They are compatible with sendmail where appropriate.
General options
--version 顯示版本信息,、配置文件位置、支持的認證方式等信息
--help 顯示幫助信息
-P, --pretend 打印當前配置,,口令將以*號顯示
-d, --debug 調試模式,會顯示與SMTP服務器的交互過程
Changing the mode of operation
-S, --serverinfo 顯示SMTP服務器的信息
This includes information about supported features (mail size
limit, authentication, TLS, DSN, ...) and about the TLS certificate (if TLS is active).
--rmqs=(host|@domain|#queue)
Send a Remote Message Queue Starting request for the
given host, domain, or queue to the SMTP server and exit.
Configuration options
-C, --file=filename 用指定的配置文件代替 ~/.msmtprc作為用戶配置文件
-a, --account=account_name 指定賬號名稱,,不指定將用default(默認賬號名稱)
This option cannot be used together with the --host option.
--host=hostname 指定SMTP服務器
This option cannot be used together with the --account option.
--port=number 指定服務器端口
--timeout=(off|seconds) 設定超時時間
--protocol=(smtp|lmtp) 設定郵件發(fā)送協(xié)議
--auth[=(on|off|method)] 指定賬號認證模式
--user=[username] 指定郵箱用戶名
--tls[=(on|off)]
Enable or disable TLS/SSL encryption.
--tls-starttls[=(on|off)]
Enable or disable STARTTLS for TLS encryption.
--tls-trust-file=[file]
Set or unset a trust file for TLS encryption.
--tls-key-file=[file]
Set or unset a key file for TLS encryption.
--tls-cert-file=[file]
Set or unset a cert file for TLS encryption.
--tls-certcheck[=(on|off)]
Enable or disable server certificate checks for TLS
encryption.
--tls-force-sslv3[=(on|off)]
Force TLS/SSL version SSLv3.
--domain=[string]
Set the argument of the SMTP EHLO (or LMTP LHLO) command.
Options specific to sendmail mode
--auto-from[=(on|off)] 自動生成from地址,,默認為off
Enable or disable automatic envelope-from addresses. The
default is off.
-f, --from=address 指定from地址,只有在auto-from為off時有效
--maildomain=[domain]
Set the domain part for generated envelope-from
addresses. It is only used when auto_from is on. See the
maildomain command below.
-N, --dsn-notify=(off|cond)
Set or unset DSN notification conditions.
-R, --dsn-return=(off|ret)
Set or unset the DSN notification amount.
--keepbcc[=(on|off)]
Enable or disable the preservation of the Bcc header.
-X, --logfile=[file] 設置日志文件
--syslog[=(on|off|facility)] 設置syslog
Enable or disable syslog logging.
-t, --read-recipients 根據(jù)郵件內容(To:中的信息)生成收件人地址,,這樣就不必有命令行中指定收件人
-- 選項結束標志,,此后的信息均被認為是收件人地址(即使它們含有-號)
The following options are accepted but ignored for sendmail compatibil-
ity:
-Btype, -bm, -Fname, -G, -hN, -i, -L tag, -m, -n, -O option=value, -ox
value, -v
三、配置文件:
配置文件有兩類,,一類是系統(tǒng)配置,,一類是用戶配置,,配置文件中的內容幾乎都可在命令行中指定。
關于SMTP服務器的信息是按賬號組織的,,每個賬號下描述了SMTP服務器的名稱(host),、認證方式(auth)、From信息,、TLS 設置等信息. 配置文件中可設置多個賬號,。
用戶可用三種方式指定賬號:
--account=id 直接指定賬號
--host=hostname 根據(jù)服務器選擇賬號
--from=address 根據(jù)from信息選擇賬號
如果以上三種方式都不用,則使用 "default"賬號
系統(tǒng)配置文件為 SYSCONFDIR/msmtprc, 其中SYSCONFDIR由所使用的平臺決定. 用 --version選項可顯示具體位置.
用戶配置文件為~/.msmtprc. 用戶配置文件中的內容會覆蓋系統(tǒng)配置文件的相同設置,。用戶配置文件的讀定權限必須為600)(chmod 600)
可配置的命令有:
defaults
defaults下設置部分項目的默認值,,若在賬號下沒有指定這些項的具體值,則采用這里指定的值
account name [:account[,...]] 設置賬號,,:表示此賬號的未指定值將從其他賬號繼承
host hostname 指定SMTP服務器
port number 指定端口
timeout (off|seconds) 指定超時
protocol (smtp|lmtp) 指定協(xié)議
auto_from [(on|off)] 是否自動生成from信息
from envelope_from 指定from信息
maildomain [domain]
Set a domain part for the generation of an envelope-from
address. This is only used when auto_from is on. The domain may
be empty.
auth [(on|off|method)] 指定認證方式,,
Available methods are plain, cram-md5, digest-md5, gssapi,
external, login, and ntlm. Note that one or more of these meth-
ods may be unavailable due to lack of support in the underlying
authentication library. Use the --version option to find out
which methods are supported.
The plain and login methods send your authentication data in
cleartext over the net
user [username] 指定用戶名
password [secret] 指定口令
If no password is set but one is needed during authentication, msmtp will try to find
it in ~/.netrc, and if that fails, msmtp will prompt you for it.
domain argument
Use this command to set the argument of the SMTP EHLO (or LMTP
LHLO) command. The default is localhost (stupid, but working).
keepbcc [(on|off)] 是否保留密送地址,默認為不保留
This command controls whether to remove or keep the Bcc header
when sending a mail. The default is to remove it.
logfile [file] 指定日志文件
syslog [(on|off|facility)] 指定SYSLOG設置
Enable or disable syslog logging. The facility can be one of
LOG_USER, LOG_MAIL, LOG_LOCAL0, ..., LOG_LOCAL7. The default is
LOG_USER.
ntlmdomain [domain]
Set a domain for the ntlm authentication method.
tls [(on|off)]
tls_starttls [(on|off)]
tls_trust_file [file]
tls_key_file [file]
tls_cert_file [file]
tls_certcheck [(on|off)]
tls_force_sslv3 [(on|off)]
dsn_notify (off|condition)
dsn_return (off|amount)
四,、配置文件示例:
Configuration file
# Set default values for all following accounts.
defaults
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
# A freemail service
account freemail
host smtp.freemail.example
from
[email protected]
auth on
user joe.smith
password secret
# A second mail address at the same freemail service
account freemail2 : freemail
from
[email protected]
# The SMTP server of the provider.
account provider
host mail.provider.example
from
[email protected]
auth on
user 123456789
password my_password
# Set a default account
account default : provider
五,、應用舉例
在設置好配置文件后,就可以在命令行下用msmtp發(fā)送郵件了,,下面是一個例子:
在shell下運行命令:msmtp -t #這里用 -t 來指定收件人,。由于msmtp要從標準輸入中讀取郵件,因此回車后,,進入輸入方式,,下面接著輸入:
to:
[email protected] #設定收件人,以便讓 -t 參數(shù)生效
subject: test #設定主題
#空行
test smtp
ctrl+D結束
隨后檢查信箱,,就會收到郵件,。