Linux
mail
目次
簡単なpostfix の設定 †
参考ページ
インストール †
sudo yum install postfix
- インストール後の選択は「インターネット。。。」を選択。
設定 †
sendmail のストップ †
service sendmail stop
chkconfig sendmail off
- mta の設定
alternatives --config mta
- chkconfig 関連の設定
chkconfig --add postfix
chkconfig postfix on
main.cf の設定 †
- 設定ファイル
sudo vi /etc/postfix/main.cf
- メーサーバーのhostname
myhostname = mail.example.com
- メールサーバーのドメイン名
mydomain = example.com
- 差出人のメールアドレスに使用されるドメイン名
$myhostname と $ を先頭につけると、変数として上で設定した myhostname の値を参照できます
myorigin = $myhostname
- メール受信を許可するアドレス
127.0.0.1 を指定してローカルから外部への配送のみを許可
inet_interfaces = 127.0.0.1
- IPv4 のみを有効にする
inet_protocols = ipv4
- メールサーバー自身に配送されたとみなすドメインのリスト
mydestination = $myhostname, localhost.$mydomain, localhost
- メールのリレー(転送)を許可するネットワーク
127.0.0.0/8 を指定してローカルからのメールのみ転送を許可
mynetworks = 127.0.0.0/8
- mail を外に送る時、既にあるローカルのメールサーバーを経由する場合
relayhost = [mail.example.com]
差出人アドレスの設定 †
postfix の起動 †
sudo /etc/init.d/postfix start
test †
mail example@example.com
. や .. 、ctrl + d で送信。
もし mail コマンドが使えない場合 †
ubuntu †
sudo apt-get install mailutils
RedHat?(CentOS) †
yum install mailx
root に届いたメールの転送。aliases の設定 †
mail user 追加、削除 †
(2)メールユーザ追加(SSHによるリモート接続もできるようにする場合)
※例としてユーザ名をcentosとする
[root@centos ~]# useradd centos ← ユーザ追加
[root@centos ~]# passwd centos ← パスワード設定
Changing password for user centos.
New UNIX password: ← パスワード応答
Retype new UNIX password: ← パスワード応答(確認)
passwd: all authentication tokens updated successfully.
以下はSMTP-Auth用ユーザ名、パスワードとシステムのユーザ名、パスワードを別々にする場合のみ
[root@centos ~]# echo "パスワード" | saslpasswd2 -p -u linux.hoge.com -c centos ← SMTP-Auth用ユーザ/パスワード登録
[root@centos ~]# sasldblistusers2 ← SMTP-Auth用ユーザ名、パスワード確認
centos@linux.hoge.com: userPassword
[root@centos ~]# chgrp postfix /etc/sasldb2 ← sasldb2所有グループをpostfixに変更※最初の1回のみ
※SMTP-Auth用ユーザ名、パスワードを削除する場合
[root@centos ~]# saslpasswd2 -d centos -u linux.hoge.com ← SMTP-Auth用ユーザ名、パスワード削除
テストメールの送信 †
echo mail †
echo test | mail root
mail (mailaddress) †
mail mailaddress@example.net
- 編集の終了、送信
- . ピリオド
- .. ピリオドピリオド
- ctrl + d のどれか
- ubuntu の mail コマンドは以下の3つ。
- mailutils
- heirloom-mailx
- bsd-mailx
/var/log/maillog が再作成されない時。 †
外部向けメールサーバ設定(CentOS6) †
参考サイト †
postfix †
postfix Install †
postfix 設定ファイルの編集 †
- vi /etc/postfix/main.cf
- 変更
myhostname = mail.tar3.net
mydomain = tar3.net
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8
relay_domains = $mydestination
relayhost = [smtp.hoge.com]:(portno) 例) [smtp.hoge.com]:587
home_mailbox = Maildir/
- 追加
#SMTPのVRFYコマンドを使用禁止
#VRFYはアカウントが実在するか確認するコマンド
#でたらめなユーザ問い合わせを行う悪質なプログラムによる
#アカウント流出を防ぐ
disable_vrfy_command = yes
#メール送信時にアカウント名・パスワードをサーバに通知し
#メールサーバから認証を受ける(SASL認証)
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/authinfo
smtp_sasl_mechanism_filter = plain
#sasl認証に対応していないメーラは拒否
broken_sasl_auth_clients = yes
#クライアントに対しての認証設定
smtp_sasl_tls_security_options = noanonymous
smtpd_sasl_security_options = noanonymous
#認証に使用するサーバを指定
smtpd_sasl_local_domain = $myhostname
#ホストの接続に関しての設定
#permit_mynetworks :クライアントIPが $mynetworks に属していた場合は要求を許可
#reject_rbl_client :RBLサイトに登録されているブラックサイトを拒否
#reject_unknown_client:クライアントIPが DNS に PTR レコードを持たない場合等に
# 要求を拒否
smtpd_client_restrictions = permit_mynetworks,
#reject_rhsbl_client rhsbl.ahbl.org,
reject_rbl_client spamcop.net,
reject_rbl_client dynablock.wirehub.net,
reject_rbl_client sbl.spamhaus.org,
reject_unknown_client,
permit
#メール中継の設定
#permit_sasl_authenticated:SMTP_AUTHに認証されたクライアントを許可
#reject_unauth_destination:以下のアドレスにマッチするものは許可
# $inet_interfaces
# $mydestination
# $virtual_alias_domains
# $virtual_mailbox_domains
# 以下のドメイン・サブドメインは許可
# $relay_domains
# 上記以外は全て拒否
smtpd_recipient_restrictions = permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
#message 上限サイズの変更
message_size_limit = 10485760
#tls setting
smtp_use_tls = yes
smtpd_tls_cert_file = /etc/postfix/tls_key/server.crt
smtpd_tls_key_file = /etc/postfix/tls_key/server.key.plain
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache
メールボックスの作成 †
- 新規ユーザー作成時
- 既存ユーザー
- ディレクトリ作成
mkdir /home/linux/Maildir
- 作成したディレクトリのパーミッション変更
chmod 700 /home/linux/Maildir
- オーナ・グループ変更
chown linux:linux /home/linux/Maildir
gmail関連の設定 †
- アプリパスワードの取得
- 2段階認証プロセスのオン
- gmailを開く
- ユーザー設定画面に入る
- 一番右上、ユーザーのアイコンをクリック、
- 「Googleアカウントを管理」をクリック
- 左側のメニューから「セキュリティ」を選択
- 「Googleへのログイン」から「2段階認証プロセス」をオンにする
- アプリパスワードの取得
- 2段階認証プロセスをオンにするとその下に「アプリパスワード」という項目が増える。
クリックする。
- 「アプリを選択」から「その他(名前を入力)」を選択
- 「Postfix」などわかりやすい名前を入力して「生成」ボタンを押す
- アプリパスワードを安全な場所にメモする
SMTP-Auth パスワードの設定 †
master.cf の編集 †
- vi /etc/postfix/master.cf
自動起動設定 †
chkconfig postfix on
chkconfig saslauthd on
起動 †
service postfix start
service saslauthd start
ルーターport の開放 †
- tcp 25
- tcp 110
- tcp 143
- tcp 587
dovecot †
dovecot Install †
dovecot 設定 †
- vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
- vi /etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = </etc/postfix/tls_key/server.crt
ssl_key = </etc/postfix/tls_key/server.key.plain
#プレインテキスト認証を許可しない
disable_plaintext_auth = yes
- vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = yes
auth_mechanisms = plain
dovecot の起動 †
service dovecot start
dovecot の自動起動設定 †
chkconfig dovecot on
thunderbird の設定 †
thunderbird smtp †
- サーバ名:今回たてたサーバ名
- ポート:587
- ユーザ名:上記認証2のユーザ名(full mail address)
- 認証方式:暗号化されたパスワード認証
- 接続の保護:なし
thunderbird pop3 †
- サーバ名:今回たてたサーバ名
- ポート:995
- ユーザ名:今回たてたサーバのユーザー名(@ マークの前)
- 認証方式:通常のパスワード認証
- 接続の保護:SSL/TLS
thunderbird imap †
- サーバ名:今回たてたサーバ名
- ポート:993
- ユーザ名:今回たてたサーバのユーザー名(@ マークの前)
- 認証方式:通常のパスワード認証
- 接続の保護:SSL/TLS
WebMail?(squirrelmail) 化 †
※PHP5.4から文字化け関連のトラブルがしんどいです。
自分は諦めてrainloopというWebMail?ソフトを使用することにしました。
文字化け参考サイト †
ここのサイトが詳しかったですが、
自分の環境では直りませんでした。。。
使用ソフト †
簡単な設定の参考サイト †
- http://www.aconus.com/~oyaji/centos/squirrelmail_centos.htm
- http://centossrv.com/squirrelmail.shtml
問題対応 †
- Error opening ../data/default_pref 対応
(以下すべて root 権限)
cd /usr/share/squirrelmail/
mkdir data
chown :[apache group] data/
cd data/
ln -s /etc/squirrelmail/default_pref default_pref
- CREATE "Sent" Reason Given: Invalid mailbox name. 対応
(以下すべて root 権限)
- WebMail? のメインページから「オプション」
- 「フォルダの設定」
- 「Trash」「Draft」「Sent」のフォルダーを選ぶ
- 「メール上限サイズ」 と 「php.ini の上限サイズ」を合わせる
- 「このページにアクセスするにはアカウントが必要です。」対応
- PHP5.4,文字化け編(参考サイト)
WebMail?(rainloop)化 †
- squirrelmailが、php5.4以降、文字化けたり色々トラブルが多いので、
squirrelmailに見切りをつけ「rainloop」というソフトでWebMail?環境を構築してみました(^^)
install †
wget http://repository.rainloop.net/v2/webmail/rainloop-latest.zip
mkdir /var/www/html/rainloop
unzip rainloop-latest.zip -d /var/www/html/rainloop
find /var/www/html/rainloop -type d -exec chmod 755 {} \;
find /var/www/html/rainloop -type f -exec chmod 644 {} \;
chown -R apache. /var/www/html/rainloop
設定 †
初回アクセスと設定 †
- https://server.tar3.net/rainloop/?admin
- デフォルトアカウント
- User name : admin
- Password : 12345
- adminパスワードの変更
- 言語の変更
- 受信するメールサーバーの設定
- Domains
- Add Domain
- あとは普通にメールサーバーの設定をします
(gmailなどは初めから設定が入ってました)
- [Login]-[Default Domain]
ユーザーでの確認 †
その他の設定 †
- 連絡帳
- mysql に rainloop のデータベースを作成し権限を与えれば使えます。
- テーマ
その他Webmailソフト †
- Roundcube