简体   繁体   中英

ArgumentError (An SMTP To address is required to send a message - Rails 4

I'm trying to send email from my application request controller based on checkbox selection. It works just find in development environment, but when I try to do it in production, I get this message :

ArgumentError (An SMTP To address is required to send a message. Set the message  smtp_envelope_to, to, cc, or bcc address.)

This is my config/environments/production looks like:

ActionMailer::Base.smtp_settings = {
    :port           => ENV['MAILGUN_SMTP_PORT'],
    :address        => ENV['MAILGUN_SMTP_SERVER'],
    :user_name      => ENV['MAILGUN_SMTP_LOGIN'],
    :password       => ENV['MAILGUN_SMTP_PASSWORD'],
    :domain         => 'https://paperthincut.herokuapp.com',
    :authentication => :plain,
  }
  ActionMailer::Base.delivery_method = :smtp
  config.action_mailer.default_url_options = { host: 'https://paperthincut.herokuapp.com' }
end

This is the only part that I can think of that's different from development environment. Does anyone have any suggestion?

update:

  def create
    @request = Request.new(request_params)
    @request.add_items_from_basket(@basket)

      if @request.save
        Basket.destroy(session[:basket_id])
        session[:basket_id] = nil
        AppMailer.request_deliver(@request).deliver
        redirect_to distributors_path
      else
        render :new
      end
  end

my app.mailer:

class AppMailer < ActionMailer::Base
  def request_deliver(request)
    @request = request
    mail smtp_envelope_to: @request.email, from: "marvkiluw@gmail.com", subject: "Order   from Marvin - In The Raw Broken Arrow"
  end
end

my collection check_boxes:

<%= f.collection_check_boxes :distributor_ids, Distributor.all, :id, :name do |cb|%>
  <% cb.label(class: "checkbox inline") {cb.check_box(class: "checkbox") + cb.text} %>
<% end %>

Look at where you make your call to the mailer, wrap that call in a if statement

if params[:your_check_box]
  call_to_mailer
end

I hope this works for you.

Keep on coding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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