Rails 3 でアプリケーションを作成し、SMTP サーバー経由でメールを送信するための簡単な連絡先ページを作成しました。問題は、アプリをローカル ホスト (PC) で実行するとメールを送信できることですが、ホストされたサーバー (hostgator) でアプリを実行すると機能しません。おもしろいことに、smtp サーバーは同じです。
これは私のローカルホストの構成です(そしてそれは動作します!):
構成/環境/developer.rb
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "mail.mydomain.org",
:port => 26,
:domain => "app.mydomain.org",
:user_name => "register@app.mydomain.org",
:password => "********",
:authentication => "plain",
:enable_starttls_auto => false
}
私のホスト サーバーの URL は app.mydomain.org であるため、ホストされたアプリではこれだけを変更しました。
config/environments/development.rb
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'mydomain.org' }
...
ホスト サーバーでは、とりあえず、開発モードで WEBrick を使用してアプリを実行します。そして、タイムアウトエラーが発生します:
....
Timeout::Error (execution expired):
app/controllers/contact_us_controller.rb:13:in `create'
...
私は何かが欠けていますか??
編集して解決:
Hostgator のサポート スタッフは、この問題の原因を突き止めました。ActionMailer
セットアップでは、は:address
である必要がありlocalhost
、 ではありませんmail.mydomain.org
。したがって、ActionMailer は次のようになります。
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 26,
:domain => "app.mydomain.org",
:user_name => "register@app.mydomain.org",
:password => "********",
:authentication => "plain",
:enable_starttls_auto => false
}