Federated service at https://msft.sts.microsoft.com/adfs/services/trust/2005/usernamemixed returned

Microsoft

I am using Graph API to send Mail. 

I have got admin consent for AAD Send.Mail permission.

 

but I'm getting this error when i trigger mail. 

(Federated service at https://msft.sts.microsoft.com/adfs/services/trust/2005/usernamemixed returned)  

Can anyone please help me.

Please check the below code which I am using.

 

string[] scopes = new string[] { "Mail.Send" };

IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.Build();

UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

SecureString password = new SecureString();
foreach (char c in emailpassword)
{
password.AppendChar(c);
}

// construct http request
var message = new Message
{
Subject = subject,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = body
},
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = toEmailId
}
}
}
};

if (ccMailId != null)
{
message.CcRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = ccMailId
}
}
};
}

var saveToSentItems = false;

await graphClient.Me.SendMail(message, saveToSentItems).Request().WithUsernamePassword(email, password).PostAsync();

2 Replies

That's a question you should be addressing to your internal IT stuff, MSIT in your case (or whatever their new name was :))

@Pathepuram_Naveen I am also facing the same issue when i use username and password authentication. Could you please let me know if the issue is been resolved or not.