feat: IMAP Email Channel (#3298)
This change allows the user to configure both IMAP and SMTP for an email inbox. IMAP enables the user to see emails in Chatwoot. And user can use SMTP to reply to an email conversation. Users can use the default settings to send and receive emails for email inboxes if both IMAP and SMTP are disabled. Fixes #2520
This commit is contained in:
9
app/jobs/inboxes/fetch_imap_email_inboxes_job.rb
Normal file
9
app/jobs/inboxes/fetch_imap_email_inboxes_job.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class Inboxes::FetchImapEmailInboxesJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform
|
||||
Inbox.where(channel_type: 'Channel::Email').all.each do |inbox|
|
||||
Inboxes::FetchImapEmailsJob.perform_later(inbox.channel) if inbox.channel.imap_enabled
|
||||
end
|
||||
end
|
||||
end
|
||||
24
app/jobs/inboxes/fetch_imap_emails_job.rb
Normal file
24
app/jobs/inboxes/fetch_imap_emails_job.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class Inboxes::FetchImapEmailsJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform(channel)
|
||||
Mail.defaults do
|
||||
retriever_method :imap, address: channel.imap_address,
|
||||
port: channel.imap_port,
|
||||
user_name: channel.imap_email,
|
||||
password: channel.imap_password,
|
||||
enable_ssl: channel.imap_enable_ssl
|
||||
end
|
||||
|
||||
new_mails = false
|
||||
|
||||
Mail.find(what: :last, count: 10, order: :desc).each do |inbound_mail|
|
||||
if inbound_mail.date.utc >= channel.imap_inbox_synced_at
|
||||
Imap::ImapMailbox.new.process(inbound_mail, channel)
|
||||
new_mails = true
|
||||
end
|
||||
end
|
||||
|
||||
Channel::Email.update(channel.id, imap_inbox_synced_at: Time.now.utc) if new_mails
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user