Authentication Issue from Desktop App, confused about Username with Token

Kenny Brownlee 0 Reputation points
2024-07-05T13:12:48.43+00:00

Trying to send email on behalf of another from Custom Desktop App.VB App, using MailKit, my code is:

        Dim app As IConfidentialClientApplication = ConfidentialClientApplicationBuilder.Create(vp_clientId) _

            .WithClientSecret(vp_clientSecret) _

            .WithAuthority(New Uri(authority)) _

        .Build()

Scopes section

Dim scopes As String() = {"https://graph.microsoft.com/.default"}

Get the Token

Dim result = app.AcquireTokenForClient(scopes).ExecuteAsync().Result

I get the token ok.

The Send Code after building my Body…

vp_SMTPsrv = "smtp-mail.outlook.com"

... Also have tried vp_SMTPsrv = "smtp-office365.com"

vp_Port = "587"

Int16.TryParse(vp_Port, vp_PortInt)

eMailClient.Connect(vp_SMTPsrv, vp_PortInt,MailKit.Security.SecureSocketOptions.StartTls)

' Remove any existing authentication mechanisms

eMailClient.AuthenticationMechanisms.Remove("NTLM")

Authenticate using the access token

Tried Both

' eMailClient.Authenticate(New MailKit.Security.SaslMechanismLogin(vp_MyEmailAddr, vp_AccessToken))

 

eMailClient.Authenticate(New MailKit.Security.SaslMechanismOAuth2(vp_MyEmailAddr, vp_AccessToken))

See Image below with api permissions.

API Permissions 

I am confused about the Username here, I only have the eMail Address that is my Azure Account, I only have Office 365 Family Account, I have tried all, but still get 535: 5.7.139 Error.

Any help, What should be my Username here?

Do I have to Setup a Office365 Business Account?

 

Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,060 questions
0 comments No comments
{count} votes