Score:0

oauth2 on office365 smtp with curl error 530 5.7.57 Client not authenticated to send mail

in flag

I am using this curl:

curl -vvv --url 'smtp://smtp.office365.com:587' \
--ssl-reqd \
--mail-from "$user" \
--mail-rcpt "$destuser" \
--upload-file ./mail.txt \
--oauth2-bearer $accesstoken

to try to send an email from an account where I registered an oauth application with these Graph Permission - Delegated Permissions

SMTP.Send
Mail.Read
Mail.Send
openid
offline_access

but I always get error: 530 5.7.57 Client not authenticated to send mail.

both the user mailbox and the transport have SmtpClientAuthenticationDisabled to $false

I am quite confident that the access token is valid, I also tested the refresh token which works, any idea on how to make this work?

Is curl compatible with https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth

?

in flag
managed to authenitcate manually with: XOAUTH2="user=$user\001auth=Bearer $token\001\001" echo -en $XOAUTH2 | base64 > encodedtoken.txt tr -d '\n' < encodedtoken.txt > encnonewline.txt helo="myserver.com" from='[email protected]' to='[email protected]' subj="subject: test mail" data=" hello test mail" encoded2=$( cat encnonewline.txt )
in flag
{ sleep 1 echo "helo $helo" sleep 0.5 echo "auth xoauth2" sleep 1 echo $encoded2 sleep 3 echo "mail from:<$from>" sleep 0.5 echo "rcpt to:<$to>" echo "data" echo "From: $from" echo "To: $to" echo "$subj" echo echo "$data" echo "." sleep 1 echo quit } | timeout 15 openssl s_client -connect smtp.office365.com:587 -crlf -starttls smtp > ./output.txt 2>&1 cat ./output.txt still need to understand how to do with curl
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.