-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1181 from codidact/configurable-emails
Configurable email senders
- Loading branch information
Showing
16 changed files
with
183 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
class AdminMailer < ApplicationMailer | ||
default from: 'Codidact Admins <[email protected]>' | ||
default from: lambda { | ||
"#{SiteSetting['ModeratorDistributionListSenderName']} " \ | ||
"<#{SiteSetting['ModeratorDistributionListSenderEmail']}>" | ||
} | ||
|
||
def to_moderators | ||
@subject = params[:subject] | ||
|
@@ -8,14 +11,19 @@ def to_moderators | |
"INNER JOIN community_users cu ON cu.user_id = u.id WHERE s.type = 'moderators' AND " \ | ||
'(u.is_global_admin = 1 OR u.is_global_moderator = 1 OR cu.is_admin = 1 OR cu.is_moderator = 1)' | ||
emails = ActiveRecord::Base.connection.execute(query).to_a.flatten | ||
mail subject: "Codidact Moderators: #{@subject}", to: '[email protected]', bcc: emails | ||
from = "#{SiteSetting['ModeratorDistributionListSenderName']} " \ | ||
"<#{SiteSetting['ModeratorDistributionListSenderEmail']}>" | ||
to = SiteSetting['ModeratorDistributionListSenderEmail'] | ||
mail subject: "Codidact Moderators: #{@subject}", to: to, from: from, bcc: emails | ||
end | ||
|
||
def to_all_users | ||
@subject = params[:subject] | ||
@body_markdown = params[:body_markdown] | ||
@users = User.where('email NOT LIKE ?', '%localhost').select(:email).map(&:email) | ||
mail subject: @subject, to: '[email protected]', from: 'Codidact Team <[email protected]>', | ||
reply_to: '[email protected]', bcc: @users | ||
to = SiteSetting['AllUsersSenderEmail'] | ||
from = "#{SiteSetting['AllUsersSenderName']} <#{SiteSetting['AllUsersSenderEmail']}>" | ||
reply_to = SiteSetting['AllUsersReplyToEmail'] | ||
mail subject: @subject, to: to, from: from, reply_to: reply_to, bcc: @users | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: 'Codidact <[email protected]>' | ||
default from: -> { "#{SiteSetting['NoReplySenderName']} <#{SiteSetting['NoReplySenderEmail']}>" } | ||
layout 'mailer' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ def donation_successful | |
@amount = params[:amount] | ||
@email = params[:email] | ||
@name = params[:name] | ||
mail from: 'Codidact Donations <[email protected]>', | ||
reply_to: 'Codidact Support <[email protected]>', | ||
to: @email, subject: 'Thanks for your donation!' | ||
from = "#{SiteSetting['DonationSenderName']} <#{SiteSetting['DonationSenderEmail']}>" | ||
reply_to = "#{SiteSetting['DonationSupportReceiverName']} <#{SiteSetting['DonationSupportReceiverEmail']}>" | ||
mail from: from, reply_to: reply_to, to: @email, subject: 'Thanks for your donation!' | ||
end | ||
|
||
def donation_uncaptured | ||
|
@@ -15,8 +15,8 @@ def donation_uncaptured | |
@email = params[:email] | ||
@name = params[:name] | ||
@intent = params[:intent] | ||
mail from: 'Codidact Donations <[email protected]>', | ||
reply_to: 'Codidact Support <[email protected]>', | ||
to: @email, subject: 'Your donation is unfinished - was everything okay?' | ||
from = "#{SiteSetting['DonationSenderName']} <#{SiteSetting['DonationSenderEmail']}>" | ||
reply_to = "#{SiteSetting['DonationSupportReceiverName']} <#{SiteSetting['DonationSupportReceiverEmail']}>" | ||
mail from: from, reply_to: reply_to, to: @email, subject: 'Your donation is unfinished - was everything okay?' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ def flag_escalated | |
.or(User.joins(:community_user) | ||
.where(community_users: { is_admin: true, community_id: @flag.community_id })) | ||
.select(:email).map(&:email) | ||
mail from: 'Codidact <[email protected]>', to: '[email protected]', bcc: emails, | ||
subject: "New flag escalation on #{@flag.community.name}" | ||
from = "#{SiteSetting['NoReplySenderName']} <#{SiteSetting['NoReplySenderEmail']}>" | ||
to = SiteSetting['NoReplySenderEmail'] | ||
mail from: from, to: to, bcc: emails, subject: "New flag escalation on #{@flag.community.name}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ def subscription | |
return | ||
end | ||
|
||
# Load request community to ensure we can access the settings/posts of the correct community | ||
RequestContext.community = @subscription.community | ||
site_name = @subscription.community.name | ||
subject = if @subscription.name.present? | ||
"Latest questions from your '#{@subscription.name}' subscription on #{site_name}" | ||
|
@@ -19,6 +21,7 @@ def subscription | |
end | ||
|
||
@subscription.update(last_sent_at: DateTime.now) | ||
mail from: 'Codidact Subscriptions <[email protected]>', to: @subscription.user.email, subject: subject | ||
from = "#{SiteSetting['SubscriptionSenderName']} <#{SiteSetting['SubscriptionSenderEmail']}>" | ||
mail from: from, to: @subscription.user.email, subject: subject | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class TwoFactorMailer < ApplicationMailer | ||
default from: 'Codidact <[email protected]>' | ||
default from: -> { "#{SiteSetting['NoReplySenderName']} <#{SiteSetting['NoReplySenderEmail']}>" } | ||
|
||
def disable_email | ||
user = params[:user] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
<%= render 'posts/markdown_script' %> | ||
|
||
<div class="notice is-danger"> | ||
<p> | ||
<i class="fas fa-exclamation-triangle"></i> Please be careful, as this tool sends a lot of emails. | ||
</p> | ||
</div> | ||
|
||
<h1><%= t 'admin.tools.email_all' %></h1> | ||
<p><%= t 'admin.email_all_blurb' %></p> | ||
|
||
<%= form_with url: send_all_email_path do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :subject, t('g.subject').capitalize, class: 'form-element' %> | ||
<%= f.text_field :subject, class: 'form-element' %> | ||
<%= f.text_field :subject, class: 'form-element', required: true %> | ||
</div> | ||
|
||
<%= render 'shared/body_field', f: f, field_name: :body_markdown, field_label: t('g.body').capitalize, post: nil %> | ||
|
||
<div class="post-preview"></div> | ||
|
||
<%= f.submit t('g.send').capitalize, class: 'button is-filled' %> | ||
<%= f.submit t('g.send').capitalize, class: 'button is-filled', | ||
onclick: "return confirm('Are you sure you want to send this email to all users?')" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
<p> | ||
We want to make sure that everything's okay. If you just changed your mind, that's absolutely fine! We're not here | ||
to push. If you ran into problems, however, please let us know if we can help — you can reply to this email to | ||
reach us at <a href="mailto:[email protected]">[email protected]</a>, or you can post on our | ||
reach us at <a href="mailto:<%= message.reply_to %>"><%= message.reply_to %></a>, or you can post on our | ||
<a href="https://meta.codidact.com/">Meta</a> site, and someone will lend a hand. | ||
</p> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ You started the process to make a donation of <%= number_to_currency(@amount, un | |
|
||
We want to make sure that everything's okay. If you just changed your mind, that's absolutely fine! We're not here | ||
to push. If you ran into problems, however, please let us know if we can help — you can reply to this email to | ||
reach us at [email protected], or you can post on our Meta site (https://meta.codidact.com/), and someone will | ||
reach us at <%= message.reply_to %>, or you can post on our Meta site (https://meta.codidact.com/), and someone will | ||
lend a hand. | ||
|
||
Whatever happened, thanks for thinking of us! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,11 @@ | |
London, UK<br/> | ||
WC2H 9JQ | ||
</p> | ||
<p><a href="mailto:[email protected]">[email protected]</a></p> | ||
<p> | ||
<a href="mailto:<%= SiteSetting['SupportReceiverEmail'] || '[email protected]' %>"> | ||
<%= SiteSetting['SupportReceiverEmail'] || '[email protected]' %> | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
</body> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,11 @@ | |
London, UK<br/> | ||
WC2H 9JQ | ||
</p> | ||
<p><a href="mailto:[email protected]">[email protected]</a></p> | ||
<p> | ||
<a href="mailto:<%= SiteSetting['SupportReceiverEmail'] || '[email protected]' %>"> | ||
<%= SiteSetting['SupportReceiverEmail'] || '[email protected]' %> | ||
</a> | ||
</p> | ||
</div> | ||
</div> | ||
</body> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
71-75 Shelton Street | ||
London, UK | ||
WC2H 9JQ | ||
[email protected] | ||
<%= SiteSetting['SupportReceiverEmail'] || '[email protected]' %> |
5 changes: 5 additions & 0 deletions
5
db/migrate/20230817213150_rename_site_setting_category_email_subscriptions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RenameSiteSettingCategoryEmailSubscriptions < ActiveRecord::Migration[7.0] | ||
def change | ||
SiteSetting.where(category: 'EmailSubscriptions').update_all(category: 'Email') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,10 +178,122 @@ | |
- name: InterestingSubscriptionScoreThreshold | ||
value: 1 | ||
value_type: integer | ||
category: EmailSubscriptions | ||
category: Email | ||
description: > | ||
The minimum score a question must have to qualify for selection for the Interesting email subscription. | ||
- name: SubscriptionSenderName | ||
value: Codidact Subscriptions | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the sender of subscription emails. | ||
- name: SubscriptionSenderEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The address to send subscription emails from (can be a fake address). | ||
Make sure your server is allowed to send email from this address, or your mails will not be received. | ||
- name: ModeratorDistributionListSenderName | ||
value: Codidact Admins | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the sender of the moderator distribution list. | ||
- name: ModeratorDistributionListSenderEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The address to send moderator distribution list emails from (can be a fake address). | ||
Make sure your server is allowed to send email from this address, or your mails will not be received. | ||
- name: NoReplySenderName | ||
value: Codidact | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the sender of no-reply emails. | ||
- name: NoReplySenderEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The address to send no-reply emails from (can be a fake address). | ||
Example uses of this address are 2FA emails, flag notifications, account emails, and more. | ||
Make sure your server is allowed to send email from this address, or your mails will not be received. | ||
- name: DonationSupportReceiverName | ||
value: Codidact Support | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the donation support email address. | ||
- name: DonationSupportReceiverEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The (real) address to receive donation support emails on. Used for users who want to reply to donation emails. | ||
- name: DonationSenderName | ||
value: Codidact Donations | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the sender of donation related emails. | ||
- name: DonationSenderEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The address to send donation related emails from (can be a fake address). | ||
Make sure your server is allowed to send email from this address, or your mails will not be received. | ||
- name: SupportReceiverName | ||
value: Codidact Support | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the donation support email address. | ||
- name: SupportReceiverEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The (real) address to receive support emails on. | ||
- name: AllUsersSenderName | ||
value: Codidact Team | ||
value_type: string | ||
category: Email | ||
description: > | ||
The name of the sender of emails sent to all users of the network via the admin tools. | ||
- name: AllUsersSenderEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The address to use as sender for emails sent to all users of the network via the admin tools (can be a fake address). | ||
Make sure your server is allowed to send email from this address, or your mails will not be received. | ||
- name: AllUsersReplyToEmail | ||
value: [email protected] | ||
value_type: string | ||
category: Email | ||
description: > | ||
The (real) address to use as reply-to for emails sent to all users of the network via the admin tools. | ||
- name: LotteryAgeDeprecationSpeed | ||
value: 0.002 | ||
value_type: float | ||
|