feat: Support Azure single-tenant application using the Graph API (#6728) (#6878)

This commit is contained in:
Tejaswini Chile
2023-06-28 08:13:08 +05:30
committed by GitHub
parent 4a770fdea7
commit d05c953eef
14 changed files with 451 additions and 13 deletions

View File

@@ -0,0 +1,26 @@
# Recently (around Feb/Mar 2023), Microsoft has made sending
# email through SMTP with Outlook near impossible, at least
# for single tenant applications.
#
# As such, adding a delivery method to use the Microsoft Graph
# API allows for emails to be sent again.
require 'base64'
class MicrosoftGraphDeliveryMethod
def initialize(config)
@config = config
end
def deliver!(mail)
# Create a new API connection, and post the mail to the `me/sendMail` endpoint.
# https://learn.microsoft.com/en-us/graph/api/user-sendmail#example-4-send-a-new-message-using-mime-format
headers = {
'Content-Type' => 'text/plain'
}
body = Base64.encode64(mail.to_s)
graph = MicrosoftGraphApi.new(@config[:token])
graph.post_to_api('me/sendMail', headers, body)
end
end