Требования к GraphAPI:
- Чтение электронной почты.
- Ответ на ту же цепочку писем
Положение о проблеме:
Я не могу опубликоватьответ поверх той же цепочки писем.Когда я это делаю, отправляется новое письмо.Но мое требование состоит в том, чтобы отправить ответ поверх существующей цепочки электронной почты.
Вывод будет выглядеть так:
Hi Team,
Это письмо было отправлено сКод GraphAPI
Спасибо
Abhijeet
Связанный код:
-- -- -- Main Method-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
static void Main(string[] args)
{
Console.Write("App started \n");
ReadingEmail.AppClientCall();
}
-- -- -- ReadingEmail.cs Class file-- -- -- -- -- -- -- -- -
class ReadingEmail {
public static GraphServiceClient client;
public static string _draftId = null;
public static void AppClientCall() {
client = GraphApiAuthenticationClient.GetAuthenticatedClientForApp();
String email = "xyz@.onmicrosoft.com";
var messages = client.Users[email].MailFolders.Inbox.Messages.Request().Select(e => new {
e.Subject,
e.IsRead,
e.Id
}).GetAsync();
if (messages.Result.Count == 0) {
Console.WriteLine("no messages in mailbox");
}
foreach(Message message in messages.Result) {
if (message.Subject.Contains("190 Report") && message.IsRead == false) {
Console.WriteLine("Found 190 Report named :" + message.Subject);
message.IsRead = true;
clsReplyAll.CreateReplyAll(message.Id); // Api Call too create draft
}
Console.WriteLine(message.Subject);
}
Console.ReadLine();
}
}
-- -- -- clsReplyAll.cs class file-- -- -- -- -- -- -- -
class clsReplyAll
{
public static GraphServiceClient client;
public static async void CreateReplyAll(string p)
{
client = GraphApiAuthenticationClient.GetAuthenticatedClientForApp();
String email = "xyz@.onmicrosoft.com";
await client.Users[email].MailFolders.Inbox.Messages[p].CreateReplyAll().Request().PostAsync();
Console.WriteLine("Inbox Id: \n" + p);
clsUpdateDraftedEmail.Update(p); // For api call to update Draft
}
}
-- -- -- clsUpdateDraftedEmail.cs-- -- -- -- -- -- -- --
class clsUpdateDraftedEmail {
public static GraphServiceClient client;
public static async void Update(string _inboxEmailid)
{
client = GraphApiAuthenticationClient.GetAuthenticatedClientForApp();
String email = "xyz@.onmicrosoft.com";
Message _msg = PrepareEmail();
var did = await client.Users[email].MailFolders.Drafts.Messages.Request()
.Select(e => new {e.Id}).GetAsync()
;
var _getDraftFileID = did.CurrentPage.First().Id;
Console.WriteLine("InboxId: \n" + _inboxEmailid + "\n");
Console.WriteLine("Draft id: \n" + _getDraftFileID);
CallGraphApiToUpdateTheDraftMessageWithBody(_getDraftFileID, _msg); // Call api to add body
}
private static Message PrepareEmail()
{
Message _msg = new Message {
Body = new ItemBody {
ContentType = BodyType.Html,
Content = "Hi Team,<br> <br>This Email is send from GraphAPI Code </br> <br>Thanks</br> <br>Abhijeet</br>"
},
InferenceClassification = InferenceClassificationType.Other
};
return _msg;
}
private static async void CallGraphApiToUpdateTheDraftMessageWithBody(string _getDraftFileID, Microsoft.Graph.Message _msg)
{
client = GraphApiAuthenticationClient.GetAuthenticatedClientForApp();
String email = "xyz@.onmicrosoft.com";
await client.Users[email].MailFolders.Drafts.Messages[_getDraftFileID].Request().UpdateAsync(_msg);
SendEmails.SendTheFileReply(_getDraftFileID);
}
}
-- -- -- SendEmails.cs-- -- -- -- -- -- -- -- -- -
class SendEmails {
public static GraphServiceClient client;
public static async void SendTheFileReply(string _getDraftFileID)
{
client = GraphApiAuthenticationClient.GetAuthenticatedClientForApp();
String email = "xyz@.onmicrosoft.com";
await client.Users[email].MailFolders.Drafts.Messages[_getDraftFileID].Send().Request().PostAsync();
Console.WriteLine("Mail Send");
}
}