2017-05-24 12 views
1

これは本当に助けが必要で、3日間これを処理しようとしています:( 私のアプリは、注文が受信されたか発送されたときにメールを送ります常にこのエラーで壊れ生産現場でのactionmailer経由でメールを送信する際に重大な問題が発生する

I, [2017-05-23T11:01:44.741054 #1060] INFO -- : Completed 500 Internal Server Error in 66ms (ActiveRecord: 4.2ms) 
F, [2017-05-23T11:01:44.743481 #1060] FATAL -- : 
SocketError (getaddrinfo: Name or service not known): 
    app/admin/order.rb:6:in `block (2 levels) in <top (required)>' 

マイactionmailerセットアップが右のようだ:。

 config.action_mailer.default_url_options = { host: 'mypage.com'} 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    address: ENV["SMTP_ADDRESS"].inspect, 
    user_name: ENV["SMTP_USER"], 
    password: ENV["SMTP_PASSWORD"], 
    domain: "mypage.com", 
    port: 587, 
    authentication: :login, 
    enable_starttls_auto: true 
    } 

ENV変数がapplication.yml

に格納されています
SMTP_ADDRESS: "smtp.gmail.com" 
SMTP_USER: "[email protected]" 
SMTP_PASSWORD: "xxxxxxxx" 

ENV変数を実行することによって確認されています:私はtelnet smtp.gmail.com 587をやった

smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com. 
gmail-smtp-msa.l.google.com has address 74.125.206.108 
gmail-smtp-msa.l.google.com has address 74.125.206.109 
gmail-smtp-msa.l.google.com has IPv6 address 2a00:1450:400c:c04::6d 

Trying 74.125.206.108... 
Connected to gmail-smtp-msa.l.google.com. 
Escape character is '^]'. 
220 smtp.gmail.com ESMTP c17sm3264999wre.35 - gsmtp 

私はポジティブresaultでhost smtp.gmail.comを行っている

Loading production environment (Rails 4.2.5) 
irb(main):001:0> puts ENV["SMTP_ADDRESS"].inspect 
"smtp.gmail.com" 
=> nil 
irb(main):002:0> 

私もやったNE nslookup smtp.gmail.com:私はここのオプションが不足してい

Server:  8.8.8.8 
Address: 8.8.8.8#53 

Non-authoritative answer: 
smtp.gmail.com canonical name = gmail-smtp-msa.l.google.com. 
Name: gmail-smtp-msa.l.google.com 
Address: 74.125.206.108 
Name: gmail-smtp-msa.l.google.com 
Address: 74.125.206.109 

が、これは完全にローカルで動作します

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }しかし、後にactionmailer休憩を展開しました。

私のGoogleアカウントでは、私はhttps://accounts.google.com/DisplayUnlockCaptchaを持っていて、less secure appsは幸運にも有効です。 6.ここ

ActiveAdmin.register Order do 

permit_params :shipped 

after_update do |order| 
    OrderNotifier.shipped(@order).deliver if order.shipped #this is line 6. 

end 

show do |order| 



    panel 'Customer Details' do 
     attributes_table_for order, :name, :email, :address, :city, :country 
    end 

    panel 'Created' do 
     "#{time_ago_in_words order.created_at} ago" 
    end 


    panel 'Shipped' do 
     order.shipped 
    end 

    panel 'Order Details' do 
     table_for(order.product_items) do 
      column 'Product' do |item| 
       item.product.title 
      end 
      column 'Quantity' do |item| 
       item.quantity 
      end 
      column 'Price Isl' do |item| 
       number_to_currency item.total_price_isl 
      end 
      column 'Price USD' do |item| 
       number_to_currency item.total_price_usd 
      end 
     end 
    end 

    panel 'Order Total USD' do 
     number_to_currency order.total_price_usd 

    end 

    panel 'Order Total Iskr' do 
     number_to_currency order.total_price_isl 

    end 

end 


end 

mailer/order_notifier.rb

class OrderNotifier < ApplicationMailer 

    default from: 'Concept Store <[email protected]>' 

    def received(order) 
    @order = order 

    mail to: order.email, subject: 'Concept Store' 
    end 


    def shipped(order) 

    @order = order 

    mail to: order.email, subject: 'Order Shipped' 
    end 
end 

答えて

3

である私は、これは、次のと同じくらい簡単ですかしら:以下

admin/order.rbが、エラーが行のために提起されたある

config.action_mailer.smtp_settings = { 
    # address: ENV["SMTP_ADDRESS"].inspect, 
    address: ENV["SMTP_ADDRESS"], 
    # ... 
} 
  • inspect(下記参照)の文字列に引用符を追加するため:

    puts "somestring" 
    # => somestring 
    puts "somestring".inspect 
    # => "somestring" 
    
+0

あなたは今日私のヒーローです:) ....それはそれは......とても簡単だったが..あなたをとても – DaudiHell

+0

に感謝しますそれがうれしい! :) –

関連する問題