Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Outlook Rest API发送带有附件的邮件_C#_Rest_Email_Outlook_Office365 Restapi - Fatal编程技术网

C# Outlook Rest API发送带有附件的邮件

C# Outlook Rest API发送带有附件的邮件,c#,rest,email,outlook,office365-restapi,C#,Rest,Email,Outlook,Office365 Restapi,我已经编写了一个应用程序,它通过一个小型控制台应用程序自动从我们的系统发送邮件,我设计该应用程序在azure中作为webjob运行。在我尝试添加附件集合之前,该应用程序发送邮件的效果非常好。指 我试图通过Attachments集合发送他们的示例代码,其中包含一个看起来像这样的对象 { “@odata.type”:“#Microsoft.OutlookServices.FileAttachment”, “名称”:“menu.txt”, “ContentBytes”:“bWFjIGFuZCBjaGV

我已经编写了一个应用程序,它通过一个小型控制台应用程序自动从我们的系统发送邮件,我设计该应用程序在azure中作为webjob运行。在我尝试添加附件集合之前,该应用程序发送邮件的效果非常好。指 我试图通过Attachments集合发送他们的示例代码,其中包含一个看起来像这样的对象

{
“@odata.type”:“#Microsoft.OutlookServices.FileAttachment”,
“名称”:“menu.txt”,
“ContentBytes”:“bWFjIGFuZCBjaGVlc2UgdG9kYXk=”
}

但是,在该api请求被拒绝并出现错误后:

{"error":{"code":"RequestBodyRead","message":"The property 'ContentBytes' does not exist on type 'Microsoft.OutlookServices.Attachment'. Make sure to only use property names that are defined by the type."}}
此外,我还花了半个小时在outlook服务支持热线上与go checkout一些论坛搭讪,并阅读了自我开始这个项目以来一直用作参考的文章,我已经放弃了这个项目。如果有人能帮助我让这个api接受这个请求,我将永远感激

这就是示例请求的外观

POST https://outlook.office.com/api/v2.0/me/sendmail
    {
      "Message": {
        "Subject": "Meet for lunch?",
        "Body": {
          "ContentType": "Text",
          "Content": "The new cafeteria is open."
        },
        "ToRecipients": [
          {
            "EmailAddress": {
              "Address": "garthf@a830edad9050849NDA1.onmicrosoft.com"
            }
          }
        ],
        "Attachments": [
          {
            "@odata.type": "#Microsoft.OutlookServices.FileAttachment",
            "Name": "menu.txt",
            "ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
          }
        ]
      },
      "SaveToSentItems": "false"
    }

我知道message对象有一个HasAttachments的bool标志,当设置为true时,它不会影响调用的结果。

根据错误消息,您使用的是“Microsoft.OutlookServices.Attachment”intead of“Microsoft.OutlookServices.FileAttachment

我也可以在使用“Microsoft.OutlookServices.Attachment”时重现此问题。 上面使用“Microsoft.OutlookServices.FileAttachment”的示例对我来说很好


请确保您正在使用“Microsoft.OutlookServices.FileAttachment”发送文本附件。

示例中的代码行与我的代码行相对应。关于你的开场白,当我提供属性->“@odata.type”:“#Microsoft.OutlookServices.FileAttachment”时,我还能做些什么来声明这是一个FileAttachment?只要属性匹配,我最后使用的类肯定是不相关的。我的意思是,当它到达Microsoft时,这是JSON。我肯定我在某个地方犯了一个愚蠢的错误,我只是不知道这到底是什么。