diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj index 67d0dea59df2526158371c0fd1e7dd9ca937ab52..98e7f4030fdc85acbc9a89ecfc8b6109103844d3 100644 --- a/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj +++ b/enterprise/backend/test/metabase_enterprise/sandbox/pulse_test.clj @@ -6,6 +6,7 @@ [medley.core :as m] [metabase-enterprise.test :as met] [metabase.api.alert :as api.alert] + [metabase.email :as email] [metabase.email.messages :as messages] [metabase.models :refer [Card Pulse PulseCard PulseChannel PulseChannelRecipient]] @@ -59,6 +60,30 @@ (m/dissoc-in results ["rasta@metabase.com" 0 :body]))) (get-in results ["rasta@metabase.com" 0 :body 0 :result])))))) +(deftest bcc-enabled-pulse-test + (testing "When bcc is not enabled, return an email that uses to:" + (mt/with-temp [Card pulse-card {} + Pulse pulse {:name "Test Pulse"} + PulseCard _ {:pulse_id (:id pulse), :card_id (:id pulse-card)} + PulseChannel pc {:channel_type :email + :pulse_id (:id pulse) + :enabled true} + PulseChannelRecipient _ {:pulse_channel_id (:id pc) + :user_id (mt/user->id :rasta)}] + (mt/with-temporary-setting-values [email-from-address "metamailman@metabase.com"] + (mt/with-fake-inbox + (with-redefs [messages/render-pulse-email (fn [_ _ _ [{:keys [result]}] _] + [{:result result}]) + email/bcc-enabled? (constantly false)] + (mt/with-test-user nil + (metabase.pulse/send-pulse! pulse))) + (let [results @mt/inbox] + (is (= {"rasta@metabase.com" [{:from "metamailman@metabase.com" + :to ["rasta@metabase.com"] + :subject "Pulse: Test Pulse"}]} + (m/dissoc-in results ["rasta@metabase.com" 0 :body]))) + (get-in results ["rasta@metabase.com" 0 :body 0 :result]))))))) + (deftest e2e-sandboxed-pulse-test (testing "Sending Pulses w/ sandboxing, end-to-end" (met/with-gtaps {:gtaps {:venues {:query (mt/mbql-query venues diff --git a/src/metabase/email.clj b/src/metabase/email.clj index 128ff239b010d55f9547c5a7c9fc68d8e94f8084..723fc2174cf66eb07b081f0c237ff498e0e261f9 100644 --- a/src/metabase/email.clj +++ b/src/metabase/email.clj @@ -29,6 +29,12 @@ (deferred-tru "The name you want to use for the sender of emails.") :visibility :settings-manager) +(defsetting bcc-enabled? + (deferred-tru "Whether or not bcc emails are enabled, default behavior is that it is") + :visibility :settings-manager + :type :boolean + :default true) + (def ^:private ReplyToAddresses [:maybe [:sequential ms/Email]]) diff --git a/src/metabase/pulse.clj b/src/metabase/pulse.clj index b3443fbdc59f49963b79af362d6d49fffe8dc565..4d22e7c53c86dc4142e7bc864ed44dbac8491877 100644 --- a/src/metabase/pulse.clj +++ b/src/metabase/pulse.clj @@ -536,7 +536,7 @@ :recipients recipients :message-type message-type :message message - :bcc? true}) + :bcc? (email/bcc-enabled?)}) (catch ExceptionInfo e (when (not= :smtp-host-not-set (:cause (ex-data e))) (throw e))))))