2017-02-21 2 views
0
using Microsoft.Graph 
IMessageAttachmentsCollectionPage Message.Attachments 

FileAttachment.ContentBytes에있는 "ContentBytes"를 가져올 수 없습니다.Microsoft.Graph 첨부 파일로 메일 보내기

내 샘플은 Microsoft https://github.com/microsoftgraph/aspnet-snippets-sample입니다.

 // Create the message. 
     Message email = new Message 
     { 
      Body = new ItemBody 
      { 
       Content = Resource.Prop_Body + guid, 
       ContentType = BodyType.Text, 
      }, 
      Subject = Resource.Prop_Subject + guid.Substring(0, 8), 
      ToRecipients = recipients, 
      HasAttachments = true, 
      Attachments = new[] 

       { 

        new FileAttachment 

        { 

         ODataType = "#microsoft.graph.fileAttachment", 

         ContentBytes = contentBytes, 

         ContentType = contentType, 

         ContentId = "testing", 

         Name = "tesing.png" 

        } 

       } 
     }; 
+0

가 소거 또는 나에게 분명히하고자합니다. 그래서, 당신이 그것을 사용하는 경우, 그것을 사용하여 첨부 파일을 보낼 수 없습니다. :) Microsoft.graph.FileAttachment가 Microsoft.Graph.IMessageAttachmentsCollectionPage로 변환 할 수 없기 때문에 내가 올바르게 말한 것입니다. – twc

답변

0

, 아래 참조 : 어셈블리 Microsoft.Graph는, 버전 = 1.2.0.0이 첨부 파일에 대한 JSON 속성을 설정하는 것이

// Create the message with attachment. 
byte[] contentBytes = System.IO.File.ReadAllBytes(@"C:\test\test.png"); 
string contentType = "image/png"; 
MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage(); 
attachments.Add(new FileAttachment 
{ 
    ODataType = "#microsoft.graph.fileAttachment", 
    ContentBytes = contentBytes, 
    ContentType = contentType, 
    ContentId = "testing", 
    Name = "testing.png" 
}); 
Message email = new Message 
{ 
    Body = new ItemBody 
    { 
     Content = Resource.Prop_Body + guid, 
     ContentType = BodyType.Text, 
    }, 
    Subject = Resource.Prop_Subject + guid.Substring(0, 8), 
    ToRecipients = recipients, 
    Attachments = attachments 
}; 

// Send the message. 
await graphClient.Me.SendMail(email, true).Request().PostAsync(); 
+0

참고 : 4MB이 방법으로 제한하기 : https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/message_post_attachments 현재 각 REST 요청의 총 크기에는 4MB 제한이 있으므로 추가 할 수있는 첨부 파일의 크기가 4MB 미만으로 제한됩니다. – twc

0

요청, 오류 메시지 또는 http 상태 코드에서 설정되는 내용을 보지 않고 정확히 무엇이 여기에 있는지 확실하지 않습니다. HasAttachments 속성을 설정할 수 없다는 것을 알고 있습니다.이 속성은 서비스에 의해서만 설정됩니다. 아, 여기서 문제는 Message.Attachments 속성을 new []으로 설정하고 새 MessageAttachmentsCollectionPage 대신에 설정하는 것입니다. 그 말로는 다음 코드를 실행했고 예상대로 작동 했으므로이 시나리오에서 서비스가 작동 할 것입니다.

 var message = await createEmail("Sent from the MailSendMailWithAttachment test."); 

     var attachment = new FileAttachment(); 
     attachment.ODataType = "#microsoft.graph.fileAttachment"; 
     attachment.Name = "MyFileAttachment.txt"; 
     attachment.ContentBytes = Microsoft.Graph.Test.Properties.Resources.textfile; 

     message.Attachments = new MessageAttachmentsCollectionPage(); 
     message.Attachments.Add(attachment); 

     await graphClient.Me.SendMail(message, true).Request().PostAsync(); 

이 정보가 도움이되기를 바랍니다.

업데이트 : 이것은 Microsoft.Graph를 사용하고 있습니다. 이 문제가 해결됩니다 위의 GitHub의에서 샘플을 사용

+0

필자는 Microsoft.graph를 사용하고 있으며 첨부 파일이 있습니다. – twc

+0

Microsoft.Graph를 사용하고 있으며 [JsonProperty (NullValueHandling = NullValueHandling.Ignore, PropertyName = "첨부 파일", Required = Required.Default)] 공용 IMessageAttachmentsCollectionPage 첨부 파일 귀하의 첨부 파일을 어떻게 사용할 수 있는지 보지 않습니다 .ODataType ... Tim : – twc

+0

Microsoft.Graph를 사용하는지 또는 Newtonsoft.Json을 사용하는지에 대해 귀하의 솔루션이 어떻게 작동하는지 보지 못합니다 - Microsoft 만 사용하고 있습니다. .Graph 및 함정으로 함정에 빠뜨릴 수 없습니다. Implicily Microsoft.graph.FileAttachment를 Microsoft.graph.IMessageAttachmentsCollectionPage로 변환하십시오. – twc

관련 문제