【问题标题】:Send Reply with attachment using Microsoft Graph API使用 Microsoft Graph API 发送带有附件的回复
【发布时间】:2019-11-02 22:31:17
【问题描述】:

我一直在使用 Microsoft graph API 来接收和回复邮件。 我已成功接收并发送邮件,但根据 Graph API 文档的回复,只能传递评论。 https://docs.microsoft.com/en-us/graph/api/message-createreply?view=graph-rest-1.0&tabs=cs

我已经开发了如下所示的发送邮件代码:-

IList<Recipient> messageToList = new List<Recipient>();
User currentUser = client.Me.Request().GetAsync().Result;

Recipient currentUserRecipient = new Recipient();

EmailAddress currentUserEmailAdress = new EmailAddress();

EmailAddress recepientUserEmailAdress = new EmailAddress();
currentUserEmailAdress.Address = currentUser.UserPrincipalName;

currentUserEmailAdress.Name = currentUser.DisplayName;
messageToList.Add(currentUserRecipient);
try

{

                ItemBody messageBody = new ItemBody();

                messageBody.Content = "A sample message from Ashish";

                messageBody.ContentType = BodyType.Text;


                Message newMessage = new Message();

                newMessage.Subject = "\nSample Mail From Ashish.";
                newMessage.ToRecipients = messageToList;
                newMessage.CcRecipients = new List<Recipient>()
                    {
                        new Recipient
                        {
                            EmailAddress = new EmailAddress
                            {
                                Address = "abc.xyz@xxxx.com"
                            }
                        }
                    };
                newMessage.Body = messageBody;




                client.Me.SendMail(newMessage, true).Request().PostAsync();
                Console.WriteLine("\nMail sent to {0}", currentUser.DisplayName);

}
catch (Exception)
{
    Console.WriteLine("\nUnexpected Error attempting to send an email");
    throw;
}

这段代码运行良好!!

有人可以分享我如何回复带有附件和邮件正文的邮件,就像我在发送邮件中所做的那样。

提前致谢。

【问题讨论】:

    标签: c# asp.net-web-api azure-ad-graph-api


    【解决方案1】:

    你必须create a replyadd the attachment,然后是send the message。使用基本的基本 /reply 端点,您无法做到这一点。

    例如:

    • 使用 POST 请求创建消息草稿

    作为响应,您将获得整个消息结构,其 id 设置为 AQMkADAwATMwMAItMTJkYi03YjFjLTAwAi0wMAoARgAAA_hRKmxc6QpJks9QJkO5R50HAP6mz4np5UJHkvaxWZjGproAAAIBDwAAAP6mz4np5UJHkvaxWZjGproAAAAUZT2jAAAA。让我们将其称为 {messageID}。

    • 之后,您可以使用 POST 请求向https://graph.microsoft.com/beta/me/messages/{messageID}/attachments 创建附件

    -在第 2 步之后,您将在邮箱草稿文件夹中看到已创建的消息。要发送它,请使用https://graph.microsoft.com/beta/me/messages/{messageID}/send

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-11
      相关资源
      最近更新 更多