blastula
blastula copied to clipboard
smtp_send failed to connect to work Outlook account
My work administration recently changed some security setting, which has broken sending emails using blastula for me.
They set up two-factor authentication, making me download the Microsoft Authenticator app to be able to use email (I could also use a phone number to get a text). I don't have any more details about what security settings they changed, I just got a popup one day to say I was locked out until I did this authentication.
Now the script I had for sending emails using blastula has stopped working. Is there a known fix for this? I read something about app passwords somewhere, but I can't find the setting for that in Outlook and I don't know if it's relevant here.
library(blastula)
create_smtp_creds_key(
"xxx@xxx",
user = "xxx@xxx",
host = "smtp.office365.com",
port = 587,
use_ssl = TRUE,
overwrite = TRUE
)
smtp_send(
compose_email(body = "hello"),
credentials = creds_key(id = "xxx@xxx"),
to = "xxx@xxx", from = "xxx@xxx"
)
Error:
Error in curl_fetch_memory(smtp_server, handle = h) :
Failed to connect to smtp.office365.com port 587: Timed out
It's because SMTP Basic Authentication doesn't work when Multi-Factor Authentication is enabled on your account (see here. You'll need to ask your IT people to register an OAuth2 app for you in the Azure Portal with the "https://outlook.office.com/SMTP.Send" permission scope. And then someone needs to update blastula to pass the OAuth2 token to curl using CURLOPT_XOAUTH2_BEARER instead of using the password. Should be an easy fix.
You can use the Microsoft365R package to send blastula mails with Outlook, assuming your org is on Microsoft 365. See the Outlook vignette.
@hongooi73 This did not fly for me. Had to request installing the Azure/Microsoft365 R SDK and was denied.
@oloverm Did you find a workaround?
No I didn’t try more after this and I’ve since moved workplaces.
From: Adam Sadowski @.> Sent: Friday, May 26, 2023 3:43:50 PM To: rstudio/blastula @.> Cc: Oliver @.>; Mention @.> Subject: Re: [rstudio/blastula] smtp_send failed to connect to work Outlook account (#271)
@olovermhttps://github.com/oloverm Did you find a workaround?
— Reply to this email directly, view it on GitHubhttps://github.com/rstudio/blastula/issues/271#issuecomment-1564501510, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGMIIMVGKA4WJ2EF7VDR443XIC6SNANCNFSM5DBUX2YQ. You are receiving this because you were mentioned.Message ID: @.***>
@galalH
It's because SMTP Basic Authentication doesn't work when Multi-Factor Authentication is enabled on your account (see here. You'll need to ask your IT people to register an OAuth2 app for you in the Azure Portal with the "https://outlook.office.com/SMTP.Send" permission scope. And then someone needs to update blastula to pass the OAuth2 token to curl using CURLOPT_XOAUTH2_BEARER instead of using the password. Should be an easy fix.
I'm new to SMTP, OAuth2, curl, etc. Is there a guide I can follow on how to go about doing the bolded?
@asadow again, consider using Microsoft365R where all of this is built in. (I assume that when you said your request was denied, that meant registering the app ID, as opposed to installing the R package... registering the app ID is going to be necessary no matter what.)