2021-11-19 06:22:27 +00:00
|
|
|
module ConversationReplyMailerHelper
|
|
|
|
def prepare_mail(cc_bcc_enabled)
|
|
|
|
@options = {
|
|
|
|
to: @contact&.email,
|
|
|
|
from: email_from,
|
|
|
|
reply_to: email_reply_to,
|
|
|
|
subject: mail_subject,
|
|
|
|
message_id: custom_message_id,
|
|
|
|
in_reply_to: in_reply_to_email
|
|
|
|
}
|
|
|
|
|
|
|
|
if cc_bcc_enabled
|
|
|
|
@options[:cc] = cc_bcc_emails[0]
|
|
|
|
@options[:bcc] = cc_bcc_emails[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
set_delivery_method
|
|
|
|
mail(@options)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_delivery_method
|
|
|
|
return unless @inbox.inbox_type == 'Email' && @channel.smtp_enabled
|
|
|
|
|
|
|
|
smtp_settings = {
|
|
|
|
address: @channel.smtp_address,
|
|
|
|
port: @channel.smtp_port,
|
2022-04-11 14:07:20 +00:00
|
|
|
user_name: @channel.smtp_login,
|
2021-11-19 06:22:27 +00:00
|
|
|
password: @channel.smtp_password,
|
|
|
|
domain: @channel.smtp_domain,
|
2022-02-08 11:26:13 +00:00
|
|
|
tls: @channel.smtp_enable_ssl_tls,
|
2021-11-19 06:22:27 +00:00
|
|
|
enable_starttls_auto: @channel.smtp_enable_starttls_auto,
|
2022-02-08 11:26:13 +00:00
|
|
|
openssl_verify_mode: @channel.smtp_openssl_verify_mode,
|
2021-11-19 06:22:27 +00:00
|
|
|
authentication: @channel.smtp_authentication
|
|
|
|
}
|
|
|
|
|
|
|
|
@options[:delivery_method] = :smtp
|
|
|
|
@options[:delivery_method_options] = smtp_settings
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_smtp_enabled
|
2022-03-25 10:35:26 +00:00
|
|
|
@inbox.inbox_type == 'Email' && @channel.smtp_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_imap_enabled
|
2021-11-19 06:22:27 +00:00
|
|
|
@inbox.inbox_type == 'Email' && @channel.imap_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_from
|
2022-04-11 14:07:20 +00:00
|
|
|
email_smtp_enabled ? @channel.email : from_email_with_name
|
2021-11-19 06:22:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def email_reply_to
|
2022-04-11 14:07:20 +00:00
|
|
|
email_imap_enabled ? @channel.email : reply_email
|
|
|
|
end
|
|
|
|
|
|
|
|
# Use channel email domain in case of account email domain is not set for custom message_id and in_reply_to
|
|
|
|
def channel_email_domain
|
|
|
|
return @account.inbound_email_domain if @account.inbound_email_domain.present?
|
|
|
|
|
|
|
|
email = @inbox.channel.try(:email)
|
|
|
|
email.present? ? email.split('@').last : raise(StandardError, 'Channel email domain not present.')
|
2021-11-19 06:22:27 +00:00
|
|
|
end
|
|
|
|
end
|