chore: Enable email channel (#1851)
This commit is contained in:
@@ -87,6 +87,14 @@ class Account < ApplicationRecord
|
||||
}
|
||||
end
|
||||
|
||||
def inbound_email_domain
|
||||
domain || GlobalConfig.get('MAILER_INBOUND_EMAIL_DOMAIN')['MAILER_INBOUND_EMAIL_DOMAIN'] || ENV.fetch('MAILER_INBOUND_EMAIL_DOMAIN', false)
|
||||
end
|
||||
|
||||
def support_email
|
||||
super || GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] || ENV.fetch('MAILER_SENDER_EMAIL', nil)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notify_creation
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
#
|
||||
# Table name: channel_email
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# email :string not null
|
||||
# forward_to_address :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer not null
|
||||
# id :bigint not null, primary key
|
||||
# email :string not null
|
||||
# forward_to_email :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_channel_email_on_email (email) UNIQUE
|
||||
# index_channel_email_on_forward_to_address (forward_to_address) UNIQUE
|
||||
# index_channel_email_on_email (email) UNIQUE
|
||||
# index_channel_email_on_forward_to_email (forward_to_email) UNIQUE
|
||||
#
|
||||
|
||||
class Channel::Email < ApplicationRecord
|
||||
@@ -21,10 +21,10 @@ class Channel::Email < ApplicationRecord
|
||||
validates :account_id, presence: true
|
||||
belongs_to :account
|
||||
validates :email, uniqueness: true
|
||||
validates :forward_to_address, uniqueness: true
|
||||
validates :forward_to_email, uniqueness: true
|
||||
|
||||
has_one :inbox, as: :channel, dependent: :destroy
|
||||
before_validation :ensure_forward_to_address, on: :create
|
||||
before_validation :ensure_forward_to_email, on: :create
|
||||
|
||||
def name
|
||||
'Email'
|
||||
@@ -36,8 +36,7 @@ class Channel::Email < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def ensure_forward_to_address
|
||||
email_domain = InstallationConfig.find_by(name: 'MAILER_INBOUND_EMAIL_DOMAIN')&.value
|
||||
self.forward_to_address ||= "#{SecureRandom.hex}@#{email_domain}"
|
||||
def ensure_forward_to_email
|
||||
self.forward_to_email ||= "#{SecureRandom.hex}@#{account.inbound_email_domain}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user