Rails 7 send mail via Microsoft Exchange SMTP using oauth2

16 views Asked by At

I was trying to send email using Microsoft Exchange email account (Outlook, 365 or whatever it is called these days) and was very surprised that regular authorization wasn't working anymore. I found out that oauth must be used instead but I can't find any clear informations on how to do that exactly.

This is the SMTP settings I have now (which works for all normal services) intercepted just before sending mail using ActiveMailer:

{
 :address=>"smtp.office365.com",
 :port=>587,
 :domain=>"example.com",
 :user_name=>"[email protected]",
 :password=>"password",
 :authentication=> :login,
 :enable_starttls=>nil,
 :enable_starttls_auto=>true,
 :openssl_verify_mode=>0,
 :ssl=>nil,
 :tls=>nil,
 :open_timeout=>25,
 :read_timeout=>25
}

Now it seems that this authentication method is no longer supported and oauth must be used instead. I also read that Microsoft Azure application is required (sic!) and it just confuses me even more. I can't find any explanation or step-by-step procedure how to actually connect to Microsoft SMTP and send mail using Active Mailer - which should be very trivial and easy to do…

I found omniauth microsoft graph gem but I'm not sure how to use it with Active Mailer and actually send email. I was trying to find gem or some example solution of using Microsoft Graph (or other solution) with ActiveMailer and no luck.

0

There are 0 answers