Chore: Move some email configs to ENV variables (#1064)

For the outgoing emails which has dependency on the incoming
part as well like the conversation continuity part, some of the
config variables used were entirely based on the account attributes.

But this is not true in case of self hosted situations where you have
multiple accounts and have a common config for incoming emails.

So moved out some of the attributes entirely dependednt on the account
to ENV with a fallback to the Global config.

Also, with this changes the name of the agent will be shown in the
email clinet with in the conversation rather than just the support
email address. This has a huge UX impact on the cutomer.

Modified all the necessary unit tests to reflect these changes.

Updated the .env.example file for the new ENV variable.
This commit is contained in:
Sony Mathew
2020-07-19 15:35:55 +05:30
committed by GitHub
parent 7ef45e5844
commit 7ca192615d
4 changed files with 33 additions and 17 deletions

View File

@@ -55,17 +55,17 @@ class ConversationReplyMailer < ApplicationMailer
def reply_email
if custom_domain_email_enabled?
"reply+#{@conversation.uuid}@#{@account.domain}"
"#{@agent.name} <reply+#{@conversation.uuid}@#{@account.domain}>"
else
@agent&.email
end
end
def from_email
if custom_domain_email_enabled? && @account.support_email.present?
@account.support_email
if custom_domain_email_enabled?
"#{@agent.name} <#{@account_support_email}>"
else
ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
"#{@agent.name} <#{ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')}>"
end
end
@@ -78,14 +78,22 @@ class ConversationReplyMailer < ApplicationMailer
end
def custom_domain_email_enabled?
@custom_domain_email_enabled ||= @account.domain_emails_enabled? && @account.domain.present?
@custom_domain_email_enabled ||= @account.domain_emails_enabled? && current_domain.present? && account_support_email.present?
end
def current_domain
if custom_domain_email_enabled? && @account.domain
@account.domain
else
GlobalConfig.get('FALLBACK_DOMAIN')['FALLBACK_DOMAIN']
@current_domain ||= begin
@account.domain ||
ENV.fetch('MAILER_INBOUND_EMAIL_DOMAIN', false) ||
GlobalConfig.get('MAILER_INBOUND_EMAIL_DOMAIN')['MAILER_INBOUND_EMAIL_DOMAIN']
end
end
def account_support_email
@account_support_email ||= begin
@account.support_email ||
GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] ||
ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
end
end
end