我正在尝试根据复选框选择从我的应用程序请求控制器发送电子邮件。它只能在开发环境中找到,但是当我尝试在生产环境中进行时,我收到了这样的信息:
ArgumentError (An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.)
这是我的配置/环境/制作看起来像:
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
这是我能想到的唯一与开发环境不同的部分。有没有人有任何建议?
更新:
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
我的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
我的收藏品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 %>
答案 0 :(得分:0)
查看您拨打邮件的地方,将该电话打包在 if语句中
if params[:your_check_box]
call_to_mailer
end
我希望这适合你。
继续编码