Hello everyone,
I have a console application in C# for to read and send e-mails and it works fine. Now I'm implementing big attachments in the messages, so, I need to create a draft message for to add the files.
The sender is the principal queue where I delegated the other queues.
This is the code for to send the messages, and it works fine.
var result = await graphClient
.Users[sender]
.SendMail(message, saveToSentItems)
.Request()
.PostResponseAsync();
This is the code for to read the exchange e-mails with attachments, and it works fine.
private IMailFolderMessagesCollectionPage RetrieveMessages(string email, string folder, string filterByData, GraphServiceClient graphClient)
{
var messages = graphClient
.Users[$"{email}"]
.MailFolders[$"{folder}"]
.Messages
.Request()
.Expand("attachments")
.Filter(filterByData)
.Top(1000)
.OrderBy("receivedDateTime asc")
.GetAsync()
.GetAwaiter()
.GetResult();
return messages;
}
But if I add this part of code for to create a draft message
var draft = await graphClient.Users[sender].Messages
.Request()
.AddAsync(message);
It returns this error:
Code: ErrorAccessDenied
Message: Access is denied. Check credentials and try again.

This is my authentication method:
public static GraphServiceClient GetGraphClient()
{
string clientId = ConfigurationManager.AppSettings["clientId"];
string tenantId = ConfigurationManager.AppSettings["tenantId"];
var scopes = new string[] { "https://graph.microsoft.com/.default" };
var principalEmail = ConfigurationManager.AppSettings["PrincipalEmail"];
var principalPassword = ConfigurationManager.AppSettings["PrincipalPassword"];
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var userName = principalEmail;
var password = principalPassword;
var userNamePasswordCredential = new UsernamePasswordCredential(userName, password, tenantId, clientId, options);
return new GraphServiceClient(userNamePasswordCredential, scopes);
}
I don't understand where the problem is, because I can send and read all e-mails, also I read e-mails in subfolders, so, I don't know where the problem is creating the draft message.
Does anyone have any idea what the problem could be?
Thanks in advance!
Horacio