Problem sending Mail via smtp-mail.outlook.com / OAUTH2 as SMTP or JSON
Hi,
I do have the problem to send mails to outlook after getting the new OAUTH2 token.
I have no problem getting the token, but after I got the token I try to send the mail thru smtp but authorization failed , please see my try to send the token thru the %Net.Authenticator mechanism %Net.SASL.XOAUTH2
Is this ok?
Or is there an other method to authenticate using the needed bearer method instead of user/pwd with the authenticator?
....code to get the token is working..
... set s=##class(%Net.SMTP).%New()
set m=##class(%Net.MailMessage).%New()
set auth=##class(%Net.Authenticator).%New()
set auth.UserName="user@..."
set meth=##class(%Net.SASL.XOAUTH2).%New()
set meth.MechanismName="XOAUTH2"
set meth.AccessToken=".....the token i got from Microsoft....sadfsafasdfasdfasdfasdfsdfs...."
set auth.Mechanism=meth
set auth.ServiceName="smtp"
set s.authenticator=auth
set s.port=587
set s.SSLConfiguration="ISC.FeatureTracker.SSL.Config"
set s.UseSTARTTLS=1
set m.Subject=SUBJECT
set m.Charset="iso-8859-1"
set m.IsHTML=1
...etc all other smtp properties....
Comments
I have been working on this same thing recently and kept running into the same problem. If you are still having issues, set the MechanismList property of the %Net.Authenticator instance to XOAUTH2 to limit the SASL authentication types the Start method of the authenticator instance looks for when it gets an AUTH response from the SMTP server.
set smtp = ##class(%Net.SMTP).%New()
set auth = ##class(%Net.Authenticator).%New()
set auth.ServiceName = "smtp"set auth.UserName = "frodob@theshire.onmicrosoft.com"set auth.MechanismList = "XOAUTH2"set auth.AccessToken = accessToken
set smtp.authenticator=auth