feat: Allow custom email address for inbox (#1336)

This commit is contained in:
Pranav Raj S 2020-10-11 23:24:11 +05:30 committed by GitHub
parent 58c0792920
commit 2c324d9421
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 9 deletions

View file

@ -15,7 +15,7 @@ class ConversationReplyMailer < ApplicationMailer
mail({
to: @contact&.email,
from: from_email,
from: from_email_with_name,
reply_to: reply_email,
subject: mail_subject,
message_id: custom_message_id,
@ -34,7 +34,7 @@ class ConversationReplyMailer < ApplicationMailer
mail({
to: @contact&.email,
from: from_email,
from: from_email_with_name,
reply_to: reply_email,
subject: mail_subject,
message_id: custom_message_id,
@ -51,7 +51,7 @@ class ConversationReplyMailer < ApplicationMailer
mail({
to: to_email,
from: from_email,
from: from_email_with_name,
subject: "[##{@conversation.display_id}] #{I18n.t('conversations.reply.transcript_subject')}"
})
end
@ -63,6 +63,7 @@ class ConversationReplyMailer < ApplicationMailer
@account = @conversation.account
@contact = @conversation.contact
@agent = @conversation.assignee
@inbox = @conversation.inbox
end
def conversation_already_viewed?
@ -90,18 +91,24 @@ class ConversationReplyMailer < ApplicationMailer
if inbound_email_enabled?
"#{assignee_name} <reply+#{@conversation.uuid}@#{current_domain}>"
else
@agent&.email
@inbox.email_address || @agent&.email
end
end
def from_email
def from_email_with_name
if inbound_email_enabled?
"#{assignee_name} <#{account_support_email}>"
else
"#{assignee_name} <#{ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')}>"
"#{assignee_name} <#{from_email_address}>"
end
end
def from_email_address
return @inbox.email_address if @inbox.email_address
ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
end
def custom_message_id
"<conversation/#{@conversation.uuid}/messages/#{@messages&.last&.id}@#{current_domain}>"
end

View file

@ -6,6 +6,7 @@
#
# id :integer not null, primary key
# channel_type :string
# email_address :string
# enable_auto_assignment :boolean default(TRUE)
# greeting_enabled :boolean default(FALSE)
# greeting_message :string

View file

@ -0,0 +1,9 @@
class AddEmailAddressToInbox < ActiveRecord::Migration[6.0]
def up
add_column :inboxes, :email_address, :string
end
def down
remove_column(:inboxes, :email_address)
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_09_27_135222) do
ActiveRecord::Schema.define(version: 2020_10_11_152227) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
@ -277,6 +277,7 @@ ActiveRecord::Schema.define(version: 2020_09_27_135222) do
t.boolean "enable_auto_assignment", default: true
t.boolean "greeting_enabled", default: false
t.string "greeting_message"
t.string "email_address"
t.index ["account_id"], name: "index_inboxes_on_account_id"
end
@ -449,11 +450,9 @@ ActiveRecord::Schema.define(version: 2020_09_27_135222) do
t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id"
t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id"
end
create_table "tags", id: :serial, force: :cascade do |t|

View file

@ -114,6 +114,18 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
end
end
context 'when inbox email address is available' do
let(:inbox) { create(:inbox, account: account, email_address: 'noreply@chatwoot.com') }
let(:conversation) { create(:conversation, assignee: agent, inbox: inbox, account: account) }
let!(:message) { create(:message, conversation: conversation, account: account) }
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
it 'set reply to email address as inbox email address' do
expect(mail.from).to eq([inbox.email_address])
expect(mail.reply_to).to eq([inbox.email_address])
end
end
context 'when the custom domain emails are enabled' do
let(:account) { create(:account) }
let(:conversation) { create(:conversation, assignee: agent, account: account).reload }