Sendmail

提供: ArchWiki
2017年10月12日 (木) 23:16時点におけるKusakata.bot (トーク | 投稿記録)による版 (文字列「Tips and tricks」を「ヒントとテクニック」に置換)
ナビゲーションに移動 検索に移動

Sendmail は unix 界の古典的な SMTP サーバーです。オリジナルのコードは、インターネットが今よりもずっと安全だった、セキュリティがあまり重要ではなかった昔に書かれました。そのため、セキュリティ上の欠陥が存在しており、セキュリティには悪評があります。ただし、セキュリティのバグは修正されたため、最近のバージョンの sendmail は他の SMTP サーバーと同じくらい安全です。それでも、セキュリティを再優先したい場合は、netqmail を使ったほうが良いでしょう。

この記事では、mysql などのデータベースを使わずに、ローカルユーザーアカウントで利用するため Sendmail をセットアップする方法を説明します。

Sendmail の設定手順しか扱っていないので、設定後に IMAP や POP3 を使えるようにしたい場合は Dovecot の記事を読んで下さい。

インストール

AUR から sendmailAUR パッケージを、公式リポジトリから procmailm4 パッケージをインストールしてください。

DNS レコード

持っているドメインの MX レコードを編集してサーバーを指定してください。MX レコードで CNAME を指定すると問題が発生することがあるので、MX からは A レコードを指定するようにするべきです。

ユーザーの追加

  • デフォルトで、全てのローカルユーザーには username@your-domain.com のようなメールアドレスが割り当てられます。シェルにアクセスしたり X でログインはせずに、メールの取得だけができるメールアカウントを追加したい場合、以下のようにして追加できます:
useradd -m -s /sbin/nologin joenobody
  • パスワードを設定:
passwd joenobody

設定

SSL 証明書の作成

警告: If you plan on implementing SSL/TLS, know that some variations and implementations are still vulnerable to attack. For details on these current vulnerabilities within SSL/TLS and how to apply appropriate changes to Sendmail, visit http://disablessl3.com/ and https://weakdh.org/sysadmin.html
  • 鍵を生成して署名してください。詳しくは OpenSSL を参照。

sendmail.cf

  • /etc/mail/sendmail.mc ファイルを作成してください。

sendmail の設定オプションについては /usr/share/sendmail-cf/README ファイルを読んで下さい。

警告: If you create your own sendmail.mc file, remember that plaintext auth over non-TLS is very risky. Using the following example forces TLS and is therefore more safe unless you know what are you doing

以下は TLS による認証を使用する例です。コメンドで中身を説明しています。コメントは dnl から始まっている行です。

/etc/mail/sendmail.mc
include(`/usr/share/sendmail-cf/m4/cf.m4')
define(`confDOMAIN_NAME', `your-domain.com')dnl
FEATURE(use_cw_file)
dnl  The following allows relaying if the user authenticates,
dnl  and disallows plaintext authentication (PLAIN/LOGIN) on
dnl  non-TLS links:
define(`confAUTH_OPTIONS', `A p y')dnl
dnl
dnl  Accept PLAIN and LOGIN authentications:
TRUST_AUTH_MECH(`LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl
dnl
dnl Make sure this paths correctly point to your SSL cert files:
define(`confCACERT_PATH',`/etc/ssl/certs')
define(`confCACERT',`/etc/ssl/cacert.pem')
define(`confSERVER_CERT',`/etc/ssl/certs/server.crt')
define(`confSERVER_KEY',`/etc/ssl/private/server.key')
dnl
FEATURE(`virtusertable', `hash /etc/mail/virtusertable.db')dnl
OSTYPE(linux)dnl
MAILER(local)dnl
MAILER(smtp)dnl
  • Then process it with
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

local-host-names

  • ドメインを local-host-names ファイルに記述してください:
/etc/mail/local-host-names
localhost
your-domain.com
mail.your-domain.com
localhost.localdomain
  • /etc/hosts ファイルでドメインを解決できるようにしてください。

access.db

  • /etc/mail/access ファイルを作成して、メールをリレーしたいベースアドレスを記述してください。10.5.0.0/24 で vpn を使っていて、その範囲の ip からのメールをリレーしたい場合:
/etc/mail/access
10.5.0 RELAY
127.0.0 RELAY
  • そして次を実行:
# makemap hash /etc/mail/access.db < /etc/mail/access

aliases.db

  • /etc/mail/aliases ファイルを編集して #root: human being here という行をアンコメントして以下のように変更:
root:         your-username
  • ユーザー名のエイリアスを追加できます:
coolguy:      your-username
somedude:     your-username
  • そして次を実行:
# newaliases

virtusertable.db

  • virtusertable ファイルを作成してエイリアスとドメインを記述してください (複数のドメインをホストする場合に有用です):
/etc/mail/virtusertable
your-username@your-domain.com         your-username
joe@my-other.tk                       joenobody
  • そして次を実行:
# makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable

ブート時に起動

以下のサービスを起動・有効化してください。詳しくはデーモンを参照。

  • saslauthd.service
  • sendmail.service
  • sm-client.service

SASL 認証

  • SMTP 認証のために SASL データベースにユーザーを追加してください:
# saslpasswd2 -c your-username

ヒントとテクニック

あるドメインのメールを全て特定のユーザーに転送

my-other.tk ドメインの全てのユーザーへのメールを your-username@your-domain.com に転送するには、/etc/mail/virtusertable ファイルに以下を追加:

@my-other.tk        your-username@your-domain.com

そして次を実行:

# makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable