3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

独自ドメインでのrails Action Mailerのエラーを直す(Postfix編)

Posted at

独自ドメイン設定の際に面倒だったのでメモ(Ubuntu 14.04)。

証明書とドメイン名が合っていないと認めません

postfixが使うサーバーの証明書とActionMailerのドメインが合っていないと

OpenSSL::SSL::SSLError (hostname *** does not match the server certificate)

と怒られる

解決策その1

SSLを使わなければいい!

config/application.rb
    config.action_mailer.smtp_settings = {
      :address => 'example.jp',
      :openssl_verify_mode  => 'none' #←これな
    }

…というのは乱暴すぎるので

解決策その2

証明書を作る

openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr

住所とかいろいろ聞かれるので適当に答える←だめ
コモンネームが重要!独自ドメインを入力する

Common Name (eg, YOUR name) []:example.jp

postfixはパスフレーズのついた証明書が読めないので解除してあげる

openssl rsa -in server.key -out server_noenc.key

コモンネームが設定できたかは以下で確認

openssl x509 -noout -text -in server.crt

Postfix側の設定

証明書ができたらPostfixに教えてあげる

/etc/postfix/main.cf
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/server.crt
smtpd_tls_key_file=/etc/ssl/private/server_noenc.key

# 下記も設定
myhostname = example.jp
mydestination = localdomain, localhost, localhost.localdomain, localhost, example.jp

設定をリロード

sudo service postfix reload

※サービス登録してない場合は起動スクリプトで^^

以上。

参照元

https://help.ubuntu.com/lts/serverguide/postfix.html
https://help.ubuntu.com/lts/serverguide/certificates-and-security.html
http://oxynotes.com/?p=4547
http://shimotori.github.io/blog-it/2013/05/15/1-rails-actionmailer-hostname-does-not-match-the-server-certificate/
https://www.geotrust.co.jp/support/ssl/csr/apache_openssl_new.html

spfも設定すると迷惑メールになりにくいのかも

お名前の場合
http://powerbiz.jp/abiz/spfrecord/archives/7763/

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?