diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aa21714..5a76373 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -195,6 +195,15 @@ module ApplicationHelper end end + def mailing_recipient_delivery_note(recipient) + if recipient.status == "failed" && recipient.error_message.present? + content_tag :div, recipient.error_message, class: "mt-1 text-xs text-rose-700 dark:text-rose-300" + elsif recipient.queued? && recipient.error_message.to_s.match?(/Da ritentare/) + content_tag :div, "Non risulta inviata. Verrà ritentata in coda.", + class: "mt-1 text-xs text-amber-800 dark:text-amber-200" + end + end + def ab_variant_badge(variant) return if variant.blank? diff --git a/app/models/mailing_recipient.rb b/app/models/mailing_recipient.rb index 6839073..ebd8e4a 100644 --- a/app/models/mailing_recipient.rb +++ b/app/models/mailing_recipient.rb @@ -91,6 +91,7 @@ class MailingRecipient < ApplicationRecord Mailings::SmtpGate.deliver do CampaignMailer.outreach(self, html: html, subject: subject_line).deliver_now end + # Solo dopo deliver_now senza eccezioni: un EOF/SMTP error non è mai un invio riuscito. record_success!(subject_line) :sent rescue *Mailings::SmtpGate::RETRYABLE => e diff --git a/app/views/mailings/show.html.erb b/app/views/mailings/show.html.erb index 4922fde..f8314ba 100644 --- a/app/views/mailings/show.html.erb +++ b/app/views/mailings/show.html.erb @@ -179,9 +179,7 @@ <% if recipient.skip_reason.present? && !recipient.pending? %>
<%= recipient.skip_reason %>
<% end %> - <% if recipient.error_message.present? %> -
<%= recipient.error_message %>
- <% end %> + <%= mailing_recipient_delivery_note(recipient) %> <% if recipient.sent_at.present? %>
Inviata <%= format_dt(recipient.sent_at) %> @@ -238,9 +236,7 @@ <% if recipient.skip_reason.present? && !recipient.pending? %>
<%= recipient.skip_reason %>
<% end %> - <% if recipient.error_message.present? %> -
<%= recipient.error_message %>
- <% end %> + <%= mailing_recipient_delivery_note(recipient) %> <% if recipient.sent_at.present? %>
Inviata <%= format_dt(recipient.sent_at) %>
<% end %> diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index a1bd69f..e77b761 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -29,4 +29,19 @@ class ApplicationHelperTest < ActionView::TestCase assert_includes html, "title=\"Società affiliata FIPAV con un testo molto lungo da accorciare\"" assert_includes html, "…" end + + test "queued SMTP retries are not shown as delivery failures" do + recipient = MailingRecipient.new(status: "queued", error_message: "Da ritentare (1/8): end of file reached") + html = mailing_recipient_delivery_note(recipient) + + assert_includes html, "Non risulta inviata" + assert_not_includes html, "end of file reached" + end + + test "failed recipients still show the SMTP error" do + recipient = MailingRecipient.new(status: "failed", error_message: "end of file reached") + html = mailing_recipient_delivery_note(recipient) + + assert_includes html, "end of file reached" + end end