我正在使用Rails API服务器,该服务器设置为为用户创建共享链接。我设置它,以便通过POST
传递一些参数,我想发送邮件,然后保存记录。我能够保存记录,但我似乎无法触发邮件。
以下是控制器上的创建操作
def create
@recipients = (share_params[:shared_with])
@recipients.each do |recipient|
ShareMailer
.share_dealsheet(recipient)
.deliver_now
end
@share = current_user.shares.create!(share_params)
json_response(@share, :created)
end
ShareMailer类
class ShareMailer < ApplicationMailer
default from: 'no-reply@dealsheetboard.com'
def share_dealsheet(recipient)
@recipient = recipient
mail(to: @recipient, subject: "Test")
end
end
还有一个样板模板保存为share_dealsheet.rb
如果我在Postman中POST
以下内容,则会保存记录,但不会触发任何邮件程序(因此我假设其他邮件程序我在创建时使用控制台中的输出)。
{
"token": "Sbdvmvt2VnzO0n3_thGSfZc1xkjs",
"shared_with":{
"1": "someemail@example.com",
"2": "anotheremail@example.com"
},
"expiry": "30 June 2017"
}
答案 0 :(得分:0)
您必须发送邮件,请参阅API以获取更多详细信息http://api.rubyonrails.org/v5.1/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Sending+mail
ShareMailer.share_dealsheet(share_params).deliver_now