Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Display bounce details for bounced emails with bounce keys (#35957)

Krzysztof Kotlarek36ae47edd28a
diff --git a/frontend/discourse/admin/templates/admin-email-logs/bounced.gjs b/frontend/discourse/admin/templates/admin-email-logs/bounced.gjs
index 47922867ca8..34b53509872 100644
--- a/frontend/discourse/admin/templates/admin-email-logs/bounced.gjs
+++ b/frontend/discourse/admin/templates/admin-email-logs/bounced.gjs
@@ -1,7 +1,18 @@
+import Component from "@glimmer/component";
+import { fn } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
import { LinkTo } from "@ember/routing";
+import { service } from "@ember/service";
import avatar from "discourse/helpers/avatar";
+import icon from "discourse/helpers/d-icon";
import formatDate from "discourse/helpers/format-date";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { bind } from "discourse/lib/decorators";
+import { i18n } from "discourse-i18n";
import EmailLogsList from "admin/components/email-logs-list";
+import IncomingEmailModal from "admin/components/modal/incoming-email";
+import IncomingEmail from "admin/models/incoming-email";
const BOUNCED_HEADERS = [
{ key: "admin.email.user" },
@@ -27,33 +38,66 @@ const BOUNCED_FILTERS = [
},
];
-export default <template>
- <EmailLogsList
- @status="bounced"
- @logType="bounced"
- @headers={{BOUNCED_HEADERS}}
- @filters={{BOUNCED_FILTERS}}
- >
- <:default as |emailLog|>
- <tr data-test-email-log-row-id={{emailLog.id}}>
- <td>{{formatDate emailLog.created_at}}</td>
- <td>
- {{#if emailLog.user}}
- <span class="email-logs-user">
- <LinkTo @route="adminUser" @model={{emailLog.user}}>
- {{avatar emailLog.user imageSize="tiny"}}
- {{emailLog.user.username}}
- </LinkTo>
- </span>
- {{else}}
- &mdash;
- {{/if}}
- </td>
- <td>
- <a href="mailto:{{emailLog.to_address}}">{{emailLog.to_address}}</a>
- </td>
- <td>{{emailLog.email_type}}</td>
- </tr>
- </:default>
- </EmailLogsList>
-</template>
+export default class AdminEmailLogsBounced extends Component {
+ @service modal;
+
+ @action
+ async showIncomingEmail(id) {
+ const model = await this.loadFromBounced(id);
+ this.modal.show(IncomingEmailModal, { model });
+ }
+
+ @bind
+ async loadFromBounced(id) {
+ try {
+ return await IncomingEmail.findByBounced(id);
+ } catch (error) {
+ popupAjaxError(error);
+ }
+ }
+
+ <template>
+ <EmailLogsList
+ @status="bounced"
+ @logType="bounced"
+ @headers={{BOUNCED_HEADERS}}
+ @filters={{BOUNCED_FILTERS}}
+ @onShowEmail={{this.showIncomingEmail}}
+ >
+ <:default
+ as |emailLog ccThreshold sortWithAddressFilter handleShowIncomingEmail|
+ >
+ <tr data-test-email-log-row-id={{emailLog.id}}>
+ <td>{{formatDate emailLog.created_at}}</td>
+ <td>
+ {{#if emailLog.user}}
+ <span class="email-logs-user">
+ <LinkTo @route="adminUser" @model={{emailLog.user}}>
+ {{avatar emailLog.user imageSize="tiny"}}
+ {{emailLog.user.username}}
+ </LinkTo>
+ </span>
+ {{else}}
+ &mdash;
+ {{/if}}
+ </td>
+ <td>
+ <a href="mailto:{{emailLog.to_address}}">{{emailLog.to_address}}</a>
+ </td>
+ <td>{{emailLog.email_type}}</td>
+ <td class="email-details">
+ {{#if emailLog.has_bounce_key}}
+ <a
+ href
+ {{on "click" (fn handleShowIncomingEmail emailLog.id)}}
+ title={{i18n "admin.email.details_title"}}
+ >
+ {{icon "circle-info"}}
+ </a>
+ {{/if}}
+ </td>
+ </tr>
+ </:default>
+ </EmailLogsList>
+ </template>
+}
diff --git a/spec/system/admin_email_logs_spec.rb b/spec/system/admin_email_logs_spec.rb
index b9cd7683cc7..f3728352765 100644
--- a/spec/system/admin_email_logs_spec.rb
+++ b/spec/system/admin_email_logs_spec.rb
@@ -72,6 +72,47 @@ RSpec.describe "Admin viewing email logs" do
expect(row).to have_email_type(email_log.email_type)
end
end
+
+ context "when bounced email has bounce key" do
+ before { SiteSetting.reply_by_email_address = "replies+%{reply_key}@example.com" }
+
+ fab!(:bounced_email_log_with_key) do
+ Fabricate(:email_log, bounced: true, email_type: "signup", bounce_key: SecureRandom.uuid)
+ end
+
+ fab!(:incoming_email) do
+ bounce_key = bounced_email_log_with_key.bounce_key
+ bounce_address = "replies+verp-#{bounce_key}@example.com"
+ Fabricate(:incoming_email, to_addresses: bounce_address, error: "550 5.1.1 User unknown")
+ end
+
+ it "displays info button and opens modal with bounce details" do
+ admin_email_logs_page.visit_bounced
+
+ row = admin_email_logs_page.row_for(bounced_email_log_with_key)
+
+ expect(row).to have_info_button
+
+ details_modal = row.open_incoming_email
+
+ expect(details_modal).to be_open
+ expect(details_modal).to have_error_message(incoming_email.error)
+ end
+ end
+
+ context "when bounced email does not have bounce key" do
+ fab!(:bounced_email_log_without_key) do
+ Fabricate(:email_log, bounced: true, email_type: "signup", bounce_key: nil)
+ end
+
+ it "does not display info button" do
+ admin_email_logs_page.visit_bounced
+
+ row = admin_email_logs_page.row_for(bounced_email_log_without_key)
+
+ expect(row).to have_no_info_button
+ end
+ end
end
describe "when viewing skipped email logs" do
diff --git a/spec/system/page_objects/pages/admin_email_logs.rb b/spec/system/page_objects/pages/admin_email_logs.rb
index ef5b189b573..ccabb3b3823 100644
--- a/spec/system/page_objects/pages/admin_email_logs.rb
+++ b/spec/system/page_objects/pages/admin_email_logs.rb
@@ -56,6 +56,21 @@ module PageObjects
end
end
+ class BouncedEmailLogRow < EmailLogRow
+ def has_info_button?
+ element.has_css?(".email-details a")
+ end
+
+ def has_no_info_button?
+ element.has_no_css?(".email-details a")
+ end
+
+ def open_incoming_email
+ element.find(".email-details a").click
+ PageObjects::Modals::AdminIncomingEmailDetailsModal.new
+ end
+ end
+
class SentEmailLogRow < EmailLogRow
def has_reply_key?(reply_key)
element.has_css?("td:nth-of-type(5) .reply-key", text: reply_key)
@@ -116,6 +131,8 @@ module PageObjects
SkippedEmailLogRow
when :sent
SentEmailLogRow
+ when :bounced
+ BouncedEmailLogRow
else
EmailLogRow
end