2017-02-21 52 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、バージョン= 1.2.0.0は、添付ファイルのJSONプロパティを設定することを私には明確か明確にしたいです。したがって、あなたがそれを使用する場合、それを使用して添付ファイルを送信することはできません。私が正しく言うなら、Microsoft.graph.FileAttachmentはMicrosoft.Graph.IMessageAttachmentsCollectionPageに変換できないからです。 – twc

答えて

0

は、以下を参照:

// 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プロパティをという新しい[]のように設定して、新しい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)] public IMessageAttachmentsCollectionPage添付ファイルどのように私はあなたのattachment.ODataTypeを使用することができます参照してください... Tim: – twc

+0

Microsoft.Graphを使用しているか、Newtonsoft.Jsonを使用している場合私はあなたのソリューションがどのように動作しているのかわかりません - 私はMicrosoft .GraphとそれをトラップすることはできませんImplicily Microsoft.graph.FileAttachmentをMicrosoft.graph.IMessageAttachmentsCollectionPageに変換します – twc

関連する問題