* Added custom Message-ID and In-Reply-To headers for conversation reply emails * Added new global config for the default domain (This is used in the above headers) * Added migration to run the config loader to load the new global config value * The subject of the conversation reply mailer was made static (This is required for threaded emails) * Added required tests
This commit is contained in:
@@ -6,6 +6,7 @@ class ConversationReplyMailer < ApplicationMailer
|
|||||||
return unless smtp_config_set_or_development?
|
return unless smtp_config_set_or_development?
|
||||||
|
|
||||||
@conversation = conversation
|
@conversation = conversation
|
||||||
|
@account = @conversation.account
|
||||||
@contact = @conversation.contact
|
@contact = @conversation.contact
|
||||||
@agent = @conversation.assignee
|
@agent = @conversation.assignee
|
||||||
|
|
||||||
@@ -15,33 +16,56 @@ class ConversationReplyMailer < ApplicationMailer
|
|||||||
@messages = recap_messages + new_messages
|
@messages = recap_messages + new_messages
|
||||||
@messages = @messages.select(&:reportable?)
|
@messages = @messages.select(&:reportable?)
|
||||||
|
|
||||||
mail(to: @contact&.email, from: from_email, reply_to: reply_email, subject: mail_subject(@messages.last))
|
mail({
|
||||||
|
to: @contact&.email,
|
||||||
|
from: from_email,
|
||||||
|
reply_to: reply_email,
|
||||||
|
subject: mail_subject(@messages.last),
|
||||||
|
message_id: custom_message_id,
|
||||||
|
in_reply_to: in_reply_to_email
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def mail_subject(last_message, trim_length = 50)
|
def mail_subject(_last_message, _trim_length = 50)
|
||||||
subject_line = last_message&.content&.truncate(trim_length) || 'New messages on this conversation'
|
subject_line = I18n.t('conversations.reply.email_subject')
|
||||||
"[##{@conversation.display_id}] #{subject_line}"
|
"[##{@conversation.display_id}] #{subject_line}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply_email
|
def reply_email
|
||||||
if custom_domain_email_enabled?
|
if custom_domain_email_enabled?
|
||||||
"reply+to+#{@conversation.uuid}@#{@conversation.account.domain}"
|
"reply+to+#{@conversation.uuid}@#{@account.domain}"
|
||||||
else
|
else
|
||||||
@agent&.email
|
@agent&.email
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_email
|
def from_email
|
||||||
if custom_domain_email_enabled? && @conversation.account.support_email.present?
|
if custom_domain_email_enabled? && @account.support_email.present?
|
||||||
@conversation.account.support_email
|
@account.support_email
|
||||||
else
|
else
|
||||||
ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def custom_message_id
|
||||||
|
"<conversation/#{@conversation.uuid}/messages/#{@messages.last.id}@#{current_domain}>"
|
||||||
|
end
|
||||||
|
|
||||||
|
def in_reply_to_email
|
||||||
|
"<account/#{@account.id}/conversation/#{@conversation.uuid}@#{current_domain}>"
|
||||||
|
end
|
||||||
|
|
||||||
def custom_domain_email_enabled?
|
def custom_domain_email_enabled?
|
||||||
@custom_domain_email_enabled ||= @conversation.account.domain_emails_enabled? && @conversation.account.domain.present?
|
@custom_domain_email_enabled ||= @account.domain_emails_enabled? && @account.domain.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_domain
|
||||||
|
if custom_domain_email_enabled? && @account.domain
|
||||||
|
@account.domain
|
||||||
|
else
|
||||||
|
GlobalConfig.get('FALLBACK_DOMAIN')['FALLBACK_DOMAIN']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,3 +14,5 @@
|
|||||||
value: 'https://www.chatwoot.com/privacy-policy'
|
value: 'https://www.chatwoot.com/privacy-policy'
|
||||||
- name: DISPLAY_MANIFEST
|
- name: DISPLAY_MANIFEST
|
||||||
value: true
|
value: true
|
||||||
|
- name: FALLBACK_DOMAIN
|
||||||
|
value: chatwoot.com
|
||||||
|
|||||||
@@ -54,3 +54,5 @@ en:
|
|||||||
typical_reply_message_body: "%{account_name} typically replies in a few hours."
|
typical_reply_message_body: "%{account_name} typically replies in a few hours."
|
||||||
ways_to_reach_you_message_body: "Give the team a way to reach you."
|
ways_to_reach_you_message_body: "Give the team a way to reach you."
|
||||||
email_input_box_message_body: "Get notified by email"
|
email_input_box_message_body: "Get notified by email"
|
||||||
|
reply:
|
||||||
|
email_subject: "New messages on this conversation"
|
||||||
|
|||||||
5
db/migrate/20200522115645_reload_config.rb
Normal file
5
db/migrate/20200522115645_reload_config.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class ReloadConfig < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
ConfigLoader.new.process
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_05_10_112339) do
|
ActiveRecord::Schema.define(version: 2020_05_22_115645) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
|||||||
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
|
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
|
||||||
|
|
||||||
it 'renders the subject' do
|
it 'renders the subject' do
|
||||||
expect(mail.subject).to eq("[##{message.conversation.display_id}] #{message.content.truncate(30)}")
|
expect(mail.subject).to eq("[##{message.conversation.display_id}] New messages on this conversation")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'not have private notes' do
|
it 'not have private notes' do
|
||||||
@@ -44,6 +44,14 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
|||||||
it 'renders the reply to email' do
|
it 'renders the reply to email' do
|
||||||
expect(mail.reply_to).to eq([message&.conversation&.assignee&.email])
|
expect(mail.reply_to).to eq([message&.conversation&.assignee&.email])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'sets the correct custom message id' do
|
||||||
|
expect(mail.message_id).to eq("<conversation/#{conversation.uuid}/messages/#{message.id}@>")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sets the correct in reply to id' do
|
||||||
|
expect(mail.in_reply_to).to eq("<account/#{conversation.account.id}/conversation/#{conversation.uuid}@>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the cutsom domain emails are enabled' do
|
context 'when the cutsom domain emails are enabled' do
|
||||||
@@ -67,6 +75,14 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
|||||||
it 'sets the from email to be the support email' do
|
it 'sets the from email to be the support email' do
|
||||||
expect(mail.from).to eq([conversation.account.support_email])
|
expect(mail.from).to eq([conversation.account.support_email])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'sets the correct custom message id' do
|
||||||
|
expect(mail.message_id).to eq("conversation/#{conversation.uuid}/messages/#{message.id}@#{conversation.account.domain}")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sets the correct in reply to id' do
|
||||||
|
expect(mail.in_reply_to).to eq("account/#{conversation.account.id}/conversation/#{conversation.uuid}@#{conversation.account.domain}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user