简体   繁体   English

在生产ROR中通过动作管理器发送邮件的严重问题

[英]serious problems sending mails via actionmailer in production ROR

I really need help with this, have been trying to work this out for 3 days :( My app is supposed to send emails to customer when order is either received or shipped but it constantly breaks with this error. 我真的需要这方面的帮助,一直试图解决这个问题3天:(我的应用程序应该在收到或发送订单时向客户发送电子邮件,但它经常打破这个错误。

  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)>'

My actionmailer setup seems to be right: 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
  }

The ENV variables are stored in the application.yml ENV变量存储在application.yml

SMTP_ADDRESS: "smtp.gmail.com"
SMTP_USER: "xxx@xxxxxxxxxx.com"
SMTP_PASSWORD: "xxxxxxxx"

The ENV variables have been checked by running: 已通过运行检查ENV变量:

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

I have done host smtp.gmail.com with positive resault: 我做了host smtp.gmail.com积极的冲击:

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

I've done telnet smtp.gmail.com 587 : 我做过telnet smtp.gmail.com 587

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

I've also done nslookup smtp.gmail.com : 我也做过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

I'm running out of options here, this works perfectly locally were config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 我在这里没有选项,这在本地完美运行是config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

But after deploy actionmailer breaks. 但经过部署actionmailer休息。

In my google account, I've https://accounts.google.com/DisplayUnlockCaptcha and enabled less secure apps with out luck. 在我的Google帐户中,我已经https://accounts.google.com/DisplayUnlockCaptcha并启用了less secure apps而运气不佳。

Below is the admin/order.rb were the error is raised for line: 6. 以下是admin/order.rb是为行提出的错误: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

here is the mailer/order_notifier.rb 这是mailer/order_notifier.rb

 class OrderNotifier < ApplicationMailer

  default from: 'Concept Store <mail@mypage.com>'

  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

I wonder if this is just as simple as the following: 我想知道这是否与以下一样简单:

config.action_mailer.smtp_settings = {
  # address: ENV["SMTP_ADDRESS"].inspect,
  address: ENV["SMTP_ADDRESS"],
  # ...
}
  • because inspect adds quotes to the string (see below): 因为inspect会在字符串中添加引号(参见下文):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM