Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Support for Microsoft Oauth in Email Channel #6227

Merged
merged 51 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f3c4fcf
fix:
tejaswinichile Dec 30, 2022
cab4aa3
fix:
tejaswinichile Dec 30, 2022
579bebc
refresh tokens and fetch the mails from ms graph
tejaswinichile Jan 3, 2023
bb5a248
fix: refresh tokens with IMAP; commented conde for the HTTParty
tejaswinichile Jan 4, 2023
3247067
refresh tokens and fetch the mails from ms graph
tejaswinichile Jan 3, 2023
d91d1dc
code cleaning, hash indifferent access fix, updated schedule class an…
tejaswinichile Jan 4, 2023
44a55ac
send email via SMTP
tejaswinichile Jan 5, 2023
c71c602
code sanity changes, addded comments and references
tejaswinichile Jan 5, 2023
7a58a70
rubocop and spec fixes
tejaswinichile Jan 6, 2023
330a36e
Feat: microsoft email channel oauth provider and fetching emails
tejaswinichile Jan 10, 2023
96368e8
minor fixes
tejaswinichile Jan 10, 2023
5f99ffa
feat: code clean up and refactoring
tejaswinichile Jan 11, 2023
48bf5b5
feat: code clean up and refactoring
tejaswinichile Jan 11, 2023
b10ccb6
Remove all the frontend code
pranavrajs Jan 12, 2023
90471d7
Merge branch 'develop' into feat/microsoft-oauth-apis
pranavrajs Jan 12, 2023
7f43ab5
feat: MS reauthorization
tejaswinichile Jan 12, 2023
cb701d6
Merge branch 'feat/microsoft-oauth-apis' of https://github.com/chatwo…
tejaswinichile Jan 12, 2023
3fe0d06
update microsoft oauth concern
tejaswinichile Jan 12, 2023
cd9e93d
PR comments changes
tejaswinichile Jan 12, 2023
d8acd5f
PR comments changes
tejaswinichile Jan 12, 2023
3c23975
Fix: Specs
tejaswinichile Jan 12, 2023
b10d0f3
Merge branch 'feat/microsoft-oauth-apis' of https://github.com/chatwo…
tejaswinichile Jan 12, 2023
8deac0f
fix: rubocop
tejaswinichile Jan 12, 2023
de416ad
fix: rubocop
tejaswinichile Jan 12, 2023
85abe97
Merge branch 'feat/microsoft-oauth-apis' of https://github.com/chatwo…
tejaswinichile Jan 12, 2023
7cc3113
Merge branch 'develop' into feat/microsoft-oauth-apis
tejaswinichile Jan 13, 2023
7521813
fix: remove comman key for redis account id setup
tejaswinichile Jan 13, 2023
d55ff39
fix: remove comman key for redis account id setup
tejaswinichile Jan 13, 2023
179fb37
fix: remove comman key for redis account id setup
tejaswinichile Jan 13, 2023
8c668f6
Merge branch 'feat/microsoft-oauth-apis' of https://github.com/chatwo…
tejaswinichile Jan 13, 2023
d5a8e05
fix: PR comments resolved
tejaswinichile Jan 13, 2023
f0bcdda
fix: moved refersh_ms_oauth_token job to service
tejaswinichile Jan 13, 2023
4b28672
chore: refactor the token service
sojan-official Jan 13, 2023
d53b077
chore: rubocop fixes
sojan-official Jan 13, 2023
2708fc2
spces for callbacks controlelr
tejaswinichile Jan 13, 2023
5d712dd
spces for callbacks controlelr
tejaswinichile Jan 13, 2023
526b83a
Merge branch 'feat/microsoft-oauth-apis' of https://github.com/chatwo…
tejaswinichile Jan 13, 2023
9d941de
Merge branch 'develop' into feat/microsoft-oauth-apis
tejaswinichile Jan 13, 2023
799f46b
fix: failing specs
tejaswinichile Jan 16, 2023
5eab1de
Merge branch 'develop' into feat/microsoft-oauth-apis
tejaswinichile Jan 16, 2023
f18d7a5
chore: remove unneccesary mocks
sojan-official Jan 16, 2023
8e55349
Merge branch 'develop' into feat/microsoft-oauth-apis
sojan-official Jan 16, 2023
908c409
chore: callback controller specs
sojan-official Jan 16, 2023
6a9f78c
chore: remove unwanted code
sojan-official Jan 16, 2023
6adebd1
chore: spec for model
sojan-official Jan 16, 2023
80d977b
chore: rubocop
sojan-official Jan 16, 2023
7da09f6
chore: more specs
sojan-official Jan 16, 2023
cae923b
chore: refactor
sojan-official Jan 16, 2023
ba09939
chore: refactor
sojan-official Jan 16, 2023
10cf72c
chore: fix specs
sojan-official Jan 16, 2023
759fecf
Merge branch 'develop' into feat/microsoft-oauth-apis
sojan-official Jan 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send email via SMTP
  • Loading branch information
tejaswinichile committed Jan 10, 2023
commit 44a55ac6d924040a5ffbd2e1691cc2262cae5e83
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@ DIRECT_UPLOADS_ENABLED=
#MS OAUTH creds
AZURE_APP_ID=
AZURE_APP_SECRET=
AZURE_SCOPES = 'offline_access https://graph.microsoft.com/IMAP.AccessAsUser.All https://graph.microsoft.com/SMTP.Send'
AZURE_SCOPES = 'Mail.Send offline_access https://graph.microsoft.com/IMAP.AccessAsUser.All https://graph.microsoft.com/SMTP.Send'
38 changes: 38 additions & 0 deletions app/helpers/api/v1/microsoft_graph_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'httparty'

# This will roll out smtp mail sender in the future
# No use as of now
module Api::V1::MicrosoftGraphHelper
GRAPH_HOST = 'https://graph.microsoft.com'.freeze

def make_api_call(method, endpoint, token, payload = nil)
headervals ||= {}
headervals[:Authorization] = "Bearer #{token}"
headervals[:Accept] = 'application/json'

params ||= {}

case method.upcase
when 'GET'
HTTParty.get "#{GRAPH_HOST}#{endpoint}",
headers: headervals,
query: params
when 'POST'
headervals['Content-Type'] = 'application/json'
HTTParty.post "#{GRAPH_HOST}#{endpoint}",
headers: headervals,
query: params,
body: payload&.to_json
else
raise "HTTP method #{method.upcase} not implemented"
end
end

def send_reply_to_mail(token, _timezone, _subject, body)
create_message_reply_url = '/v1.0/me/sendMail'

mail_body = body

make_api_call 'POST', create_message_reply_url, token, mail_body
end
end
4 changes: 2 additions & 2 deletions app/jobs/inboxes/fetch_imap_emails_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def fetch_mail_for_ms_oauth_channel(channel)
imap.authenticate('XOAUTH2', channel.imap_login, access_token)
imap.select('INBOX')

yesterday = (Date.today - 1).strftime('%d-%b-%Y')
tomorrow = (Date.today + 1).strftime('%d-%b-%Y')
yesterday = (Time.zone.today - 1).strftime('%d-%b-%Y')
tomorrow = (Time.zone.today + 1).strftime('%d-%b-%Y')
imap.search(['BEFORE', tomorrow, 'SINCE', yesterday]).each do |message_id|
inbound_mail = Mail.read_from_string imap.fetch(message_id, 'RFC822')[0].attr['RFC822']

Expand Down
28 changes: 26 additions & 2 deletions app/mailers/conversation_reply_mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@ def prepare_mail(cc_bcc_enabled)
@options[:cc] = cc_bcc_emails[0]
@options[:bcc] = cc_bcc_emails[1]
end

ms_smtp_settings
set_delivery_method

mail(@options)
end

private

def ms_smtp_settings
return unless @inbox.email? && @channel.imap_enabled && @inbox.channel.provider == 'microsoft'

smtp_settings = {
address: 'smtp.office365.com',
port: 587,
user_name: @channel.imap_login,
password: @channel.provider_config['access_token'],
domain: 'smtp.office365.com',
tls: false,
enable_starttls_auto: true,
openssl_verify_mode: 'none',
authentication: 'xoauth2'
}

@options[:delivery_method] = :smtp
@options[:delivery_method_options] = smtp_settings
end

def set_delivery_method
return unless @inbox.inbox_type == 'Email' && @channel.smtp_enabled

Expand Down Expand Up @@ -47,8 +67,12 @@ def email_imap_enabled
@inbox.inbox_type == 'Email' && @channel.imap_enabled
end

def email_microsoft_auth_enabled
@inbox.inbox_type == 'Email' && @channel.provider == 'microsoft'
end

def email_from
email_smtp_enabled ? @channel.email : from_email_with_name
email_microsoft_auth_enabled || email_smtp_enabled ? @channel.email : from_email_with_name
end

def email_reply_to
Expand Down