在C#中创建带有附件的草稿的示例? [英] Example of creating a draft with an attachment in C#?

查看:107
本文介绍了在C#中创建带有附件的草稿的示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用C#编写了一个测试应用程序,该应用程序使用新的Gmail API创建了邮件草稿.当邮件没有附件时,它可以正常工作.

I've written a test application in C# that creates a draft message using the new Gmail API. It works fine when the message has no attachment.

我从IMAP API移出,并已将MailBee.NET组件与该API一起使用. MailBee.NET组件包括一个生成RFC 2822消息的类,因此我已重复使用该类并对其进行了Base64编码,并已将其分配给"Raw"属性,如下所述:

I'm moving from the IMAP API and have used the MailBee.NET components with that API. The MailBee.NET components includes a class that produces an RFC 2822 message, so I've re-used this and have Base64-encoded the message and have assigned to the "Raw" property as described here:

https://developers.google.com/gmail/api/guides/drafts

        MailMessage msg = new MailMessage();
        msg.Subject = "test!";
        msg.BodyPlainText = "Test content";
        msg.Attachments.Add(@"D:\Trace.log", "Trace.log", Guid.NewGuid().ToString(), null, null, NewAttachmentOptions.Inline, MailTransferEncoding.Base64);

        Message m = new Message();
        m.Raw = Convert.ToBase64String(msg.GetMessageRawData());

        Draft d = new Draft();
        d.Message = m;
        d = gs.Users.Drafts.Create(d, "me").Execute();

在不添加任何附件的情况下,它可以正常工作,但是在添加附件时却失败,并返回500:

It works fine when no attachment is added, but fails with a 500 response when one is added:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Backend Error"
   }
  ],
  "code": 500,
  "message": "Backend Error"
 }
}

有人可以提供使用.NET API进行操作的示例吗? API页面上的示例是非常准系统,实际上并没有提供太多有用的信息,因此文档也不是很好.最好使用.NET客户端随附的Message/MessagePart/MessagePartBody类,但是我找不到关于它们使用的任何明确指导或示例,因此不知道从哪里开始.

Could somebody please provide an example of how to do this using the .NET API? The example on the API page is very barebones and doesn't really give much in the way of useful information and the documentation isn't great. It would probably be best to use the Message / MessagePart / MessagePartBody classes included with the .NET Client, however I can't find any clear guidance or examples on their use so don't know where to begin.

问题:

1)谁能提供使用.NET Client中的类创建带有附件的草稿消息的示例代码?

1) Can anybody provide some example code of creating a draft message with an attachment using the classes within the .NET Client?

2)可以附加多个文件吗?该文档通篇始终引用一个文件,而多部分"指南恰好涉及两个部分:元数据和附件.

2) Is it possible to attach more than one file? The documentation refers to a single file throughout and the Multipart guidance refers to exactly two parts: metadata and attachment.

推荐答案

提供您要上载的示例原始"字段绝对有助于调试(使用base64编码或直接进行调试).

Providing a sample "raw" field that you're uploading would definitely be helpful to debug (either base64 encoded or just directly).

但这听起来与以下内容有关: GMail API:无法在草稿中添加附件

However this sounds related to: GMail API : unable to add an attachment in a draft

这篇关于在C#中创建带有附件的草稿的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆