0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 15:18:34 +08:00
discourse/app/mailers/group_smtp_mailer.rb
David Battersby 1450851538
FIX: allow custom email sender name via translation overrides (#40674)
The translation key for email_from was mistakenly removed in #36974 as
it was thought to be redundant since we were dropping the "via site
name" text from notification emails. However we should still allow sites
to override this.

This change restores the translation key for `email_from` and adds a new
`email_from_group` to allow overriding these values.

Both keys also whitelist `site_name` for interpolation, despite omitting
it from the default translation.
2026-06-09 14:03:03 +04:00

76 lines
2.7 KiB
Ruby
Vendored

# frozen_string_literal: true
class GroupSmtpMailer < ActionMailer::Base
include Email::BuildEmailHelper
def send_mail(from_group, to_address, post, cc_addresses: nil, bcc_addresses: nil)
raise "SMTP is disabled" if !SiteSetting.enable_smtp
op_incoming_email = post.topic.first_post.incoming_email
recipient_user = User.find_by_email(to_address, primary: true)
delivery_options = {
address: from_group.smtp_server,
port: from_group.smtp_port,
domain: from_group.email_username_domain,
user_name: from_group.email_username,
password: from_group.email_password,
# NOTE: Might be better at some point to store this authentication method in the database
# against the group.
authentication: SmtpProviderOverrides.authentication_override(from_group.smtp_server),
enable_starttls_auto: from_group.smtp_ssl_mode == Group.smtp_ssl_modes[:starttls],
enable_ssl: from_group.smtp_ssl_mode == Group.smtp_ssl_modes[:ssl_tls],
return_response: true,
open_timeout: GlobalSetting.group_smtp_open_timeout.to_f,
read_timeout: GlobalSetting.group_smtp_read_timeout.to_f,
}
group_name = from_group.name_full_preferred
build_email(
to_address,
message: post.raw,
url: post.url(without_slug: SiteSetting.private_email?),
post_id: post.id,
topic_id: post.topic_id,
context: "",
username: post.user.username,
group_name: group_name,
allow_reply_by_email: true,
only_reply_by_email: true,
use_from_address_for_reply_to: SiteSetting.enable_smtp && from_group.smtp_enabled?,
private_reply: post.topic.private_message?,
participants: UserNotifications.participants(post, recipient_user, reveal_staged_email: true),
include_respond_instructions: true,
template: "user_notifications.user_posted_pm",
use_topic_title_subject: true,
topic_title: op_incoming_email&.subject || post.topic.title,
add_re_to_subject: !post.is_first_post?,
locale: SiteSetting.default_locale,
delivery_method_options: delivery_options,
from: from_group.smtp_from_address,
from_alias: I18n.t("email_from_group", group_name: group_name, site_name: Email.site_title),
html_override: html_override(post),
cc: cc_addresses,
bcc: bcc_addresses,
)
end
private
def html_override(post)
UserNotificationRenderer.render(
template: "email/notification",
format: :html,
locals: {
context_posts: nil,
reached_limit: nil,
post: post,
in_reply_to_post: nil,
classes: Rtl.new(nil).css_class,
first_footer_classes: "",
reply_above_line: true,
},
)
end
end