如果 ActionMailer 中的 bcc 地址为空,如何停止发送到 :to 地址的 mail 操作?
How to stop `mail` action sending to `:to` address if :bcc addresses are empty in ActionMailer?
我有一个 actinmailer 方法,如果 @receiver
符合某些条件并且存在 @default_mail
,则会填充该方法。它将邮件发送给 BCC 中的收件人和 to
字段中的 default_mail。具体如下:
def mail_users
@default_mail = "user@gmail.com"
@latest_listing_mail= Equipment.joins(:user).last.user.email
@wanted_req_mail = WantedEquipment.where(sub_category_id: "#{a}", status: 2).pluck(:email)
@wanted_req_mail.include? @latest_listing_mail
if true
@receiver = @wanted_req_mail.delete(@latest_listing_mail)
@receiver = @wanted_req_mail
mail(bcc: @receiver, to: @default_mail)
end
end
我不希望 mail
在 @receiver
为空时执行。我该如何实现?
只需添加一个条件
mail(bcc: @receiver, to: @default_mail) if @receiver.present?
您可能想删除此条件
if true # doesn't make sense
end
我有一个 actinmailer 方法,如果 @receiver
符合某些条件并且存在 @default_mail
,则会填充该方法。它将邮件发送给 BCC 中的收件人和 to
字段中的 default_mail。具体如下:
def mail_users
@default_mail = "user@gmail.com"
@latest_listing_mail= Equipment.joins(:user).last.user.email
@wanted_req_mail = WantedEquipment.where(sub_category_id: "#{a}", status: 2).pluck(:email)
@wanted_req_mail.include? @latest_listing_mail
if true
@receiver = @wanted_req_mail.delete(@latest_listing_mail)
@receiver = @wanted_req_mail
mail(bcc: @receiver, to: @default_mail)
end
end
我不希望 mail
在 @receiver
为空时执行。我该如何实现?
只需添加一个条件
mail(bcc: @receiver, to: @default_mail) if @receiver.present?
您可能想删除此条件
if true # doesn't make sense
end