「Msmtp」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(文字列「http://www.mail-archive.com/」を「https://www.mail-archive.com/」に置換)
(→‎Cronie のデフォルトメールクライアント: aliasesとcrontabとの設定を二者択一にするために「または:」を挿入。cronのページと同一表現とした。)
タグ: visualeditor
(2人の利用者による、間の4版が非表示)
1行目: 1行目:
 
{{Lowercase title}}
 
{{Lowercase title}}
 
[[Category:メールクライアント]]
 
[[Category:メールクライアント]]
[[Category:メールサーバー]]
 
 
[[en:Msmtp]]
 
[[en:Msmtp]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|mutt}}
 
{{Related|mutt}}
 
{{Related|OfflineIMAP}}
 
{{Related|OfflineIMAP}}
  +
{{Related|SSMTP}}
  +
{{Related|S-nail}}
  +
{{Related|OpenSMTPD}}
 
{{Related articles end}}
 
{{Related articles end}}
   
[http://msmtp.sourceforge.net/ msmtp] はとてもシンプルで使いやすい SMTP クライアントです。[[Wikipedia:sendmail|sendmail]] と完全な互換性があります。
+
[http://msmtp.sourceforge.net/ msmtp] はとてもシンプルで使いやすい SMTP クライアントです。[[sendmail]] と完全な互換性があります。
   
== インストール ==
+
==インストール==
   
msmtp は {{Pkg|msmtp}} パッケージで[[インストール]]できます。さらに {{Pkg|msmtp-mta}} をインストールすることで msmtp に sendmail エイリアスが作成されます。
+
{{Pkg|msmtp}} パッケージで[[インストール]]できます。さらに {{Pkg|msmtp-mta}} をインストールすることで msmtp に sendmail エイリアスが作成されます。
   
== 基本設定 ==
+
==基本設定==
   
 
以下は msmtp の設定例です (パッケージに含まれている、{{ic|/usr/share/doc/msmtp/msmtprc-user.example}} にある通常ユーザーのサンプルが基になっています。システム設定ファイルは {{ic|/etc/msmtprc}} にあり、サンプルは {{ic|/usr/share/doc/msmtp/msmtprc-system.example}} にあります):
 
以下は msmtp の設定例です (パッケージに含まれている、{{ic|/usr/share/doc/msmtp/msmtprc-user.example}} にある通常ユーザーのサンプルが基になっています。システム設定ファイルは {{ic|/etc/msmtprc}} にあり、サンプルは {{ic|/usr/share/doc/msmtp/msmtprc-system.example}} にあります):
60行目: 62行目:
 
}}
 
}}
   
== mail コマンドを使う ==
+
==mail コマンドを使う==
   
 
{{ic|mail}} コマンドを使ってメールを送信するには {{Pkg|s-nail}} パッケージをインストールする必要があります。それに加えて {{ic|sendmail}} 互換の MTA が必要です。{{Pkg|msmtp-mta}} をインストールするか {{ic|/etc/mail.rc}} を編集して sendmail クライアントを設定してください:
 
{{ic|mail}} コマンドを使ってメールを送信するには {{Pkg|s-nail}} パッケージをインストールする必要があります。それに加えて {{ic|sendmail}} 互換の MTA が必要です。{{Pkg|msmtp-mta}} をインストールするか {{ic|/etc/mail.rc}} を編集して sendmail クライアントを設定してください:
   
{{hc|/etc/mail.rc|2=set sendmail=/usr/bin/msmtp}}
+
{{hc|/etc/mail.rc|2=set mta=/usr/bin/msmtp}}
   
 
システム共通の {{ic|/etc/msmtprc}} ファイルを使用するか、{{ic|.msmtprc}} ファイルをメールを送信したい全てのユーザーのホームディレクトリに配置する必要があります。
 
システム共通の {{ic|/etc/msmtprc}} ファイルを使用するか、{{ic|.msmtprc}} ファイルをメールを送信したい全てのユーザーのホームディレクトリに配置する必要があります。
82行目: 84行目:
 
default: admin@domain.example}}
 
default: admin@domain.example}}
   
== 動作のテスト ==
+
==動作のテスト==
   
 
アカウントオプション ({{ic|1=--account=,-a}}) で送信元として使用するアカウントを指定します:
 
アカウントオプション ({{ic|1=--account=,-a}}) で送信元として使用するアカウントを指定します:
99行目: 101行目:
   
 
{{Tip|Gmail を使用する場合、以下のどちらかの設定が必要です:
 
{{Tip|Gmail を使用する場合、以下のどちらかの設定が必要です:
  +
* 2段階認証を使用する場合: [https://myaccount.google.com/apppasswords アプリパスワードを作成する]。
* ''Settings'' > ''Security'' で "Less Secure Apps" を許可する。他の Gmail アカウントはサインアウトする必要があります。Google アカウントのセキュリティ設定では複数のアカウントの設定を同時に管理することはできません。
 
  +
* 使用しない場合: [https://myaccount.google.com/lesssecureapps セキュアでないアプリを許可する] (非推奨)。
* 2段階認証を有効にしてアプリパスワードを作成する。
 
 
}}
 
}}
 
{{Tip|''-a default'' の代わりに ''--read-envelope-from'' を使うことで送信するメッセージの ''From:'' に使われるアカウントが自動的に選択されます。}}
 
{{Tip|''-a default'' の代わりに ''--read-envelope-from'' を使うことで送信するメッセージの ''From:'' に使われるアカウントが自動的に選択されます。}}
   
== Cronie のデフォルトメールクライアント ==
+
==Cronie のデフォルトメールクライアント==
   
 
{{Pkg|cronie}} で sendmail ではなく msmtp を使うようにするには、{{Pkg|msmtp-mta}} をインストールするか、{{ic|cronie.service}} systemd ユニットを編集してください:
 
{{Pkg|cronie}} で sendmail ではなく msmtp を使うようにするには、{{Pkg|msmtp-mta}} をインストールするか、{{ic|cronie.service}} systemd ユニットを編集してください:
114行目: 116行目:
 
それから cronie あるいは msmtp にメールアドレスを設定してください:
 
それから cronie あるいは msmtp にメールアドレスを設定してください:
   
* {{ic|/etc/msmtprc}} に追加: {{bc|aliases /etc/aliases}} それから {{ic|/etc/aliases}} を作成: {{bc|your_username: email@address.com}}
+
*{{ic|/etc/msmtprc}} に追加: {{bc|aliases /etc/aliases}} それから {{ic|/etc/aliases}} を作成: {{bc|your_username: email@address.com}}または:
* crontab の {{ic|MAILTO}} 行に追加: {{bc|MAILTO=email@address.com}}
+
*crontab の {{ic|MAILTO}} 行に追加: {{bc|MAILTO=email@address.com}}
   
== パスワード管理 ==
+
==パスワード管理==
   
 
msmtp のパスワードはプレーンテキスト・暗号化ファイル・キーリングのどれかに保存できます [http://msmtp.sourceforge.net/doc/msmtp.html#Authentication]。
 
msmtp のパスワードはプレーンテキスト・暗号化ファイル・キーリングのどれかに保存できます [http://msmtp.sourceforge.net/doc/msmtp.html#Authentication]。
   
=== GNOME Keyring ===
+
===GNOME Keyring===
   
 
[[GNOME Keyring]] にパスワードを保存することができます。Wiki ページに従ってキーリングを設定したら {{Pkg|libsecret}} をインストールしてください。以下のコマンドでパスワードを保存できます:
 
[[GNOME Keyring]] にパスワードを保存することができます。Wiki ページに従ってキーリングを設定したら {{Pkg|libsecret}} をインストールしてください。以下のコマンドでパスワードを保存できます:
129行目: 131行目:
 
msmtp は自動的にパスワードを確認します。
 
msmtp は自動的にパスワードを確認します。
   
=== GnuPG ===
+
===GnuPG===
   
  +
{{Ic|password}} ディレクティブは省略できます。省略した場合、アカウントの {{Ic|auth}} を {{Ic|off}} 以外の値に設定することで、インタラクティブシェルから msmtp を起動したときにメールの送信前にパスワードが要求されるようになります。[[Mutt]] などの他のアプリケーションから呼び出されたときは msmtp はパスワードを要求しません。そのようなときは {{ic|--passwordeval}} パラメータを使って [[GnuPG]] などの外部のキーリングツールを使用することができます。
The {{Ic|password}} directive may be omitted. In that case, if the account in question has {{Ic|auth}} set to a legitimate value other than {{Ic|off}}, invoking msmtp from an interactive shell will ask for the password before sending mail. msmtp will not prompt if it has been called by another type of application, such as [[Mutt]]. For such cases, the {{ic|--passwordeval}} parameter
 
can be used to call an external keyring tool like [[GnuPG]].
 
   
  +
[[GnuPG]] と [[GnuPG#gpg-agent|gpg-agent]] を設定してパスワードを毎回入力しなくてもよいようにしてください。それから、以下のように msmtp 用に暗号化したパスワードファイルを作成してください。{{ic|700}} パーミッションで [[tmpfs]] 上にディレクトリを作成することで、ディスクに暗号化されていないパスワードが書き込まれないようにすることができます。ディレクトリの中にはメールアカウントのパスワードを記述したプレーンテキストファイルを作成してください。そして、秘密鍵を使ってファイルを暗号化してください:
To do this, set up [[GnuPG]], including [[GnuPG#gpg-agent|gpg-agent]] to avoid having to enter the password every time. Then, create an encrypted password file for msmtp, as follows. Create a secure directory with {{ic|700}} permissions located on a [[tmpfs]] to avoid writing the unencrypted password to the disk. In that directory create a plain text file with the mail account password. Then, encrypt the file with your private key:
 
   
 
$ gpg --default-recipient-self -e ''/path/to/plain/password''
 
$ gpg --default-recipient-self -e ''/path/to/plain/password''
   
  +
プレーンテキストファイルを削除して、暗号化したファイルを適切なディレクトリに移動してください (例: {{ic|~/.mail/.msmtp-credentials.gpg}})。{{ic|~/.msmtprc}} に以下を追加:
Remove the plain text file and move the encrypted file to the final location, e.g. {{ic|~/.mail/.msmtp-credentials.gpg}}. In {{ic|~/.msmtprc}} add:
 
   
 
{{hc|~/.msmtprc|passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.mail/.msmtp-credentials.gpg"}}
 
{{hc|~/.msmtprc|passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.mail/.msmtp-credentials.gpg"}}
   
  +
[[Mutt]] などからメールを送信するときに GUI のパスワードプロンプトを表示するだけなら上記で十分です。gpg によってパスフレーズのプロンプトが表示されない場合、先に [[GPG#gpg-agent|gpg-agent]] を起動してください。muttrc に {{ic| ` command ` }} のようにバッククォートを使って外部コマンドを指定することでエージェントを起動できます。例:
Normally this is sufficient for a GUI password prompt to appear when, for example, sending a message from [[Mutt]]. If gpg prompt for the passphrase cannot be issued, then start the [[GPG#gpg-agent|gpg-agent]] before. A simple hack to start the agent is to execute a external command in your muttrc using the backtick {{ic| ` command ` }} syntax. For example, you can put something like the following in your muttrc
 
   
 
{{hc|muttrc|set my_msmtp_pass=`gpg -d mypwfile.gpg`}}
 
{{hc|muttrc|set my_msmtp_pass=`gpg -d mypwfile.gpg`}}
   
 
Mutt will execute this when it starts, gpg-agent will cache your password, msmtp will be happy and you can send mail.
 
Mutt will execute this when it starts, gpg-agent will cache your password, msmtp will be happy and you can send mail.
{{Note| If you do this, you will have to restart mutt after gpg-agent clears the password to start sending emails again}}
 
   
  +
{{Note| If you do this, you will have to restart mutt after gpg-agent clears the password to start sending emails again}}
If you cannot use a keyring tool for any reason, you may want to use the password directly. There is a patched version {{AUR|msmtp-pwpatched}}{{Broken package link|{{aur-mirror|msmtp-pwpatched}}}} in the AUR that provides the {{ic|--password}} parameter. Note that it is a '''huge security flaw''', since any user connected to you machine can see the parameter of any command (in the /proc filesystem for example).
 
   
If this is not desired, an alternative is to place passwords in {{ic|~/.netrc}}, a file that can act as a common pool for msmtp, [[OfflineIMAP]], and associated tools.
+
An alternative is to place passwords in {{ic|~/.netrc}}, a file that can act as a common pool for msmtp, [[OfflineIMAP]], and associated tools.
   
== ヒントとテクニック ==
+
==ヒントとテクニック==
   
 
===msmtp をオフラインで使う===
 
===msmtp をオフラインで使う===
   
  +
msmtp は素晴らしいツールですが、使用するにはオンラインになる必要があります。インターネットに常時接続することができないノートパソコンなどではあまり好ましくありません。この問題を解決するためのスクリプトが複数存在し、まとめて msmtpqueue と呼ばれます。
Although msmtp is great, it requires that you be online to use it. This isn't ideal for people on laptops with intermittent connections to the Internet or dialup users. Several scripts have been written to remedy this fact, collectively called msmtpqueue.
 
   
The scripts are installed under {{ic|/usr/share/doc/msmtp/msmtpqueue}}. You might want to copy the scripts to a convenient location on your computer, ({{ic|/usr/local/bin}} is a good choice).
+
スクリプトは {{ic|/usr/share/doc/msmtp/msmtpqueue}} にインストールされます。スクリプトはどこか便利な場所にコピーすると良いでしょう ({{ic|/usr/local/bin}} を推奨します)
   
Finally, change your MUA to use msmtp-enqueue.sh instead of msmtp when sending e-mail. By default, queued messages will be stored in {{ic|~/.msmtpqueue}}. To change this location, change the {{ic|QUEUEDIR=$HOME/.msmtpqueue}} line in the scripts (or delete the line, and export the QUEUEDIR variable in {{ic|.bash_profile}} like so: {{ic|export QUEUEDIR="$XDG_DATA_HOME/msmtpqueue"}}).
+
そして MUA でメールを送信するときに msmtp のかわりに msmtp-enqueue.sh を使うようにしてください。デフォルトでは、キューに入ったメッセージは {{ic|~/.msmtpqueue}} に保存されます。保存場所を変更したい場合はスクリプトの {{ic|QUEUEDIR=$HOME/.msmtpqueue}} 行を変更してください (もしくは行を削除して、{{ic|.bash_profile}} QUEUEDIR 変数をエクスポートしてください: {{ic|export QUEUEDIR="$XDG_DATA_HOME/msmtpqueue"}})
   
  +
作成したメールを送信したいときは以下のコマンドを実行:
When you want to send any mail that you've created and queued up run:
 
 
$ /usr/local/bin/msmtp-runqueue.sh
 
$ /usr/local/bin/msmtp-runqueue.sh
   
  +
{{ic|/usr/local/bin}} を PATH に追加することでキーストロークを少なくすることができます。スクリプトに付属している README ファイルには有用な情報が載っているため、読むことを推奨します。
Adding {{ic|/usr/local/bin}} to your PATH can save you some keystrokes if you're doing it manually. The README file that comes with the scripts has some handy information, reading it is recommended.
 
   
 
===Vim のシンタックスハイライト===
 
===Vim のシンタックスハイライト===
msmtp のソースディストリビューションには [[Vim]] 用の {{ic|msmtprc}} のシンタックスハイライトスクリプトが含まれています。{{ic|/usr/share/vim/vimfiles/syntax/msmtp.vim}} で利用できます。ファイルタイプは自動的に認識されません。[http://vimdoc.sourceforge.net/htmldoc/options.html#modeline modeline] をファイルの一番上に追加するのが簡単です:
+
msmtp のソースディストリビューションには [[Vim]] 用の {{ic|msmtprc}} のシンタックスハイライトスクリプトが含まれています。{{ic|/usr/share/vim/vimfiles/syntax/msmtp.vim}} で利用できます。ファイルタイプは自動的に認識されません。[http://vimdoc.sourceforge.net/htmldoc/options.html#modeline modeline] をファイルの一番上あるいは下に追加するのが簡単です:
   
 
# vim:filetype=msmtp
 
# vim:filetype=msmtp
192行目: 192行目:
 
?>
 
?>
 
}}
 
}}
  +
  +
===Gmail で XOAUTH2 認証を使う===
  +
msmtp は現在 OAUTH2 認証をサポートしていません。Gmail で XOAUTH2 認証を使うには ([https://developers.google.com/gmail/imap/xoauth2-protocol 公式情報] を参照)、AUR の {{AUR|msmtp-oauth2}} パッケージをインストールしてください。平文認証で {{ic|AUTH PLAIN ...}} の代わりに {{ic|AUTH XOAUTH2 password}} を送信するというハックが含まれており、平文認証が無効になり XOAUTH2 が有効になります。設定例:
  +
{{bc|
  +
account gmail
  +
host smtp.gmail.com
  +
port 587
  +
from your@gmail_login_email
  +
tls on
  +
tls_starttls on
  +
tls_certcheck off
  +
auth plain
  +
user any_thing_here
  +
passwordeval "get-gmail-token"
  +
logfile ~/.msmtp.log
  +
}}
  +
The {{ic|get-gmail-token}} script can be found from the source files of the AUR package. See more information on [https://www.bytereef.org/howto/oauth2/getmail.html getmail link] about how this works. And see [https://developers.google.com/gmail/api/quickstart/python Gmail API quickstart] for instruction on registering a Gmail APP and authorizing it to access emails.
   
 
==トラブルシューティング==
 
==トラブルシューティング==
213行目: 230行目:
   
 
===Server sent empty reply===
 
===Server sent empty reply===
"server sent empty reply" エラーが表示される場合、以下{{ic|~/.msmtprc}} に追加してください:
+
"server sent empty reply" エラーが表示される場合、メールサーバーがポート 587 で STARTTLS 許可しておらず、非標準のポート 465 での SSL/TLS を必要としています [https://www.fastmail.com/help/technical/ssltlsstarttls.html]。
   
  +
msmtp でポート 465 の SSL/TLS を使うには、以下の行を {{ic|~/.msmtprc}} に追加してください:
tls_starttls off
 
   
  +
tls_starttls off
上記の設定で msmtp で STARTTLS (ポート 587) のかわりに SSL/TLS (ポート 465) が使われるようになります [https://www.fastmail.com/help/technical/ssltlsstarttls.html]。
 
   
 
===GSSAPI の問題===
 
===GSSAPI の問題===

2019年11月27日 (水) 11:49時点における版

関連記事

msmtp はとてもシンプルで使いやすい SMTP クライアントです。sendmail と完全な互換性があります。

インストール

msmtp パッケージでインストールできます。さらに msmtp-mta をインストールすることで msmtp に sendmail エイリアスが作成されます。

基本設定

以下は msmtp の設定例です (パッケージに含まれている、/usr/share/doc/msmtp/msmtprc-user.example にある通常ユーザーのサンプルが基になっています。システム設定ファイルは /etc/msmtprc にあり、サンプルは /usr/share/doc/msmtp/msmtprc-system.example にあります):

~/.msmtprc
# Set default values for all following accounts.
defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.msmtp.log

# Gmail
account        gmail
host           smtp.gmail.com
port           587
from           username@gmail.com
user           username
password       plain-text-password

# A freemail service
account        freemail
host           smtp.freemail.example
from           joe_smith@freemail.example
...

# Set a default account
account default : gmail
ノート: SSL/TLS を使っていて "Server sent empty reply" エラーメッセージが表示される場合、#Server sent empty reply を見て下さい。

ユーザーの設定ファイルは所有者が読み書きできるように明示的に設定しないと msmtp がエラーを吐きます:

$ chmod 600 ~/.msmtprc

設定ファイルに平文でパスワードを保存したくない場合、passwordeval を使って外部プログラムを起動するか、あるいは下のパスワード管理セクションを見てください。以下は GnuPG を使ってパスワードを暗号化する例です:

$ echo -e "password\n" | gpg --encrypt -o .msmtp-gmail.gpg # enter id (email...)
警告: ほとんどのシェルはコマンド履歴を保存します (例: .bash_history.zhistory)。GPG でシェルの標準入力を使いたくない場合 gpg --encrypt -o .msmtp-gmail.gpg -r <email> - コマンドを使ってください。最後のダッシュは打ち間違えではなく標準入力を使うために必要な文字です。コマンドを実行したら、パスワードを入力してから Control-d を押せば GPG によってパスワードが暗号化されます。
~/.msmtprc
passwordeval    "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.msmtp-gmail.gpg"

mail コマンドを使う

mail コマンドを使ってメールを送信するには s-nail パッケージをインストールする必要があります。それに加えて sendmail 互換の MTA が必要です。msmtp-mta をインストールするか /etc/mail.rc を編集して sendmail クライアントを設定してください:

/etc/mail.rc
set mta=/usr/bin/msmtp

システム共通の /etc/msmtprc ファイルを使用するか、.msmtprc ファイルをメールを送信したい全てのユーザーのホームディレクトリに配置する必要があります。

msmtp ではエイリアスが使えます。以下の行を msmtprc のデフォルトセクションかローカルの設定ファイルに追加してください:

/etc/msmtprc
aliases               /etc/aliases

そして /etc にエイリアスファイルを作成してください:

/etc/aliases
# Example aliases file
     
# Send root to Joe and Jane
root: joe_smith@example.com, jane_chang@example.com
   
# Send everything else to admin
default: admin@domain.example

動作のテスト

アカウントオプション (--account=,-a) で送信元として使用するアカウントを指定します:

$ echo "hello there username." | msmtp -a default username@domain.com

もしくは、ファイルにアドレスを書いて使用するには:

To: username@domain.com
From: username@gmail.com
Subject: A test

Hello there.
$ cat test.mail | msmtp -a default <username>@domain.com
ヒント: Gmail を使用する場合、以下のどちらかの設定が必要です:
ヒント: -a default の代わりに --read-envelope-from を使うことで送信するメッセージの From: に使われるアカウントが自動的に選択されます。

Cronie のデフォルトメールクライアント

cronie で sendmail ではなく msmtp を使うようにするには、msmtp-mta をインストールするか、cronie.service systemd ユニットを編集してください:

/etc/systemd/system/cronie.service.d/msmtp.conf
[Service]
ExecStart=
ExecStart=/usr/bin/crond -n -m '/usr/bin/msmtp -t'

それから cronie あるいは msmtp にメールアドレスを設定してください:

  • /etc/msmtprc に追加:
    aliases /etc/aliases
    それから /etc/aliases を作成:
    your_username: email@address.com
    または:
  • crontab の MAILTO 行に追加:
    MAILTO=email@address.com

パスワード管理

msmtp のパスワードはプレーンテキスト・暗号化ファイル・キーリングのどれかに保存できます [1]

GNOME Keyring

GNOME Keyring にパスワードを保存することができます。Wiki ページに従ってキーリングを設定したら libsecret をインストールしてください。以下のコマンドでパスワードを保存できます:

$ secret-tool store --label=msmtp host smtp.your.domain service smtp user yourusername

msmtp は自動的にパスワードを確認します。

GnuPG

password ディレクティブは省略できます。省略した場合、アカウントの authoff 以外の値に設定することで、インタラクティブシェルから msmtp を起動したときにメールの送信前にパスワードが要求されるようになります。Mutt などの他のアプリケーションから呼び出されたときは msmtp はパスワードを要求しません。そのようなときは --passwordeval パラメータを使って GnuPG などの外部のキーリングツールを使用することができます。

GnuPGgpg-agent を設定してパスワードを毎回入力しなくてもよいようにしてください。それから、以下のように msmtp 用に暗号化したパスワードファイルを作成してください。700 パーミッションで tmpfs 上にディレクトリを作成することで、ディスクに暗号化されていないパスワードが書き込まれないようにすることができます。ディレクトリの中にはメールアカウントのパスワードを記述したプレーンテキストファイルを作成してください。そして、秘密鍵を使ってファイルを暗号化してください:

$ gpg --default-recipient-self -e /path/to/plain/password

プレーンテキストファイルを削除して、暗号化したファイルを適切なディレクトリに移動してください (例: ~/.mail/.msmtp-credentials.gpg)。~/.msmtprc に以下を追加:

~/.msmtprc
passwordeval  "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.mail/.msmtp-credentials.gpg"

Mutt などからメールを送信するときに GUI のパスワードプロンプトを表示するだけなら上記で十分です。gpg によってパスフレーズのプロンプトが表示されない場合、先に gpg-agent を起動してください。muttrc に ` command ` のようにバッククォートを使って外部コマンドを指定することでエージェントを起動できます。例:

muttrc
set my_msmtp_pass=`gpg -d mypwfile.gpg`

Mutt will execute this when it starts, gpg-agent will cache your password, msmtp will be happy and you can send mail.

ノート: If you do this, you will have to restart mutt after gpg-agent clears the password to start sending emails again

An alternative is to place passwords in ~/.netrc, a file that can act as a common pool for msmtp, OfflineIMAP, and associated tools.

ヒントとテクニック

msmtp をオフラインで使う

msmtp は素晴らしいツールですが、使用するにはオンラインになる必要があります。インターネットに常時接続することができないノートパソコンなどではあまり好ましくありません。この問題を解決するためのスクリプトが複数存在し、まとめて msmtpqueue と呼ばれます。

スクリプトは /usr/share/doc/msmtp/msmtpqueue にインストールされます。スクリプトはどこか便利な場所にコピーすると良いでしょう (/usr/local/bin を推奨します)。

そして MUA でメールを送信するときに msmtp のかわりに msmtp-enqueue.sh を使うようにしてください。デフォルトでは、キューに入ったメッセージは ~/.msmtpqueue に保存されます。保存場所を変更したい場合はスクリプトの QUEUEDIR=$HOME/.msmtpqueue 行を変更してください (もしくは行を削除して、.bash_profile で QUEUEDIR 変数をエクスポートしてください: export QUEUEDIR="$XDG_DATA_HOME/msmtpqueue")。

作成したメールを送信したいときは以下のコマンドを実行:

$ /usr/local/bin/msmtp-runqueue.sh

/usr/local/bin を PATH に追加することでキーストロークを少なくすることができます。スクリプトに付属している README ファイルには有用な情報が載っているため、読むことを推奨します。

Vim のシンタックスハイライト

msmtp のソースディストリビューションには Vim 用の msmtprc のシンタックスハイライトスクリプトが含まれています。/usr/share/vim/vimfiles/syntax/msmtp.vim で利用できます。ファイルタイプは自動的に認識されません。modeline をファイルの一番上あるいは下に追加するのが簡単です:

# vim:filetype=msmtp

msmtp を使って PHP でメールを送信

php.inisendmail_path オプションを以下のように編集してください:

sendmail_path = "/usr/bin/msmtp -C /path/to/your/config -t"

Note that you can not use a user configuration file (ie: one under ~/) if you plan on using msmtp as a sendmail replacement with php or something similar. In that case just create /etc/msmtprc, and remove your user configuration (or not if you plan on using it for something else). Also make sure it's readable by whatever you're using it with (php, django, etc...)

From the msmtp manual: Accounts defined in the user configuration file override accounts from the system configuration file. The user configuration file must have no more permissions than user read/write

So it's impossible to have a conf file under ~/ and have it still be readable by the php user.

To test it place this file in your php enabled server or using php-cli.

<?php
mail("your@email.com", "Test email from PHP", "msmtp as sendmail for PHP");
?>

Gmail で XOAUTH2 認証を使う

msmtp は現在 OAUTH2 認証をサポートしていません。Gmail で XOAUTH2 認証を使うには (公式情報 を参照)、AUR の msmtp-oauth2AUR パッケージをインストールしてください。平文認証で AUTH PLAIN ... の代わりに AUTH XOAUTH2 password を送信するというハックが含まれており、平文認証が無効になり XOAUTH2 が有効になります。設定例:

account gmail
host smtp.gmail.com
port 587
from your@gmail_login_email
tls on
tls_starttls on
tls_certcheck off
auth plain
user any_thing_here
passwordeval "get-gmail-token"
logfile ~/.msmtp.log

The get-gmail-token script can be found from the source files of the AUR package. See more information on getmail link about how this works. And see Gmail API quickstart for instruction on registering a Gmail APP and authorizing it to access emails.

トラブルシューティング

TLS の問題

以下のエラーメッセージが表示される場合:

msmtp: TLS certificate verification failed: the certificate hasn't got a known issuer

おそらく tls_trust_file が正しくありません。

Just follow the fine manual. It explains you how to find out the server certificate issuer of a given smtp server. Then you can explore the /usr/share/ca-certificates/ directory to find out if by any chance, the certificate you need is there. If not, you will have to get the certificate on your own. If you are using your own certificate, you can make msmtp trust it by adding the following to your ~/.msmtprc:

tls_fingerprint <SHA1 (recommended) or MD5 fingerprint of the certificate>

If you are trying to send mail through GMail and are receiving this error, have a look at this thread or just use the second GMail example above.

If you are completely desperate, but are 100% sure you are communicating with the right server, you can always temporarily disable the cert check:

$ msmtp --tls-certcheck off

以下のメッセージが表示される場合:

 msmtp: TLS handshake failed: the operation timed out

FS#44994 のバグが原因です。--with-ssl=openssl を使って msmtp を再コンパイルしてください (デフォルトでは GnuTLS が有効になっています)。

Server sent empty reply

"server sent empty reply" エラーが表示される場合、メールサーバーがポート 587 での STARTTLS を許可しておらず、非標準のポート 465 での SSL/TLS を必要としています [2]

msmtp でポート 465 の SSL/TLS を使うには、以下の行を ~/.msmtprc に追加してください:

tls_starttls off

GSSAPI の問題

以下のエラーが表示される場合:

GNU SASL: GSSAPI error in client while negotiating security context in gss_init_sec_context() in SASL library.  This is most likely due insufficient credentials or malicious interactions.

.msmtprc ファイルの auth 設定を gssapi から plain に変更してみてください [3]:

auth plain