C# Mailjet SDK : Adding attachment

标签 c# sdk attachment mailjet

我正在使用官方 C# Mailjet SDK ( https://github.com/mailjet/mailjet-apiv3-dotnet )。到目前为止工作正常。

但是如何添加附件呢?

我明白了

Mailjet.Client.Resources

有 InlineAttachments 和 Attachments,但我该如何使用它?

这是到目前为止的代码片段:

        MailjetRequest request = new MailjetRequest { Resource = Send.Resource }
            .Property(Send.FromEmail, emailOperatable.FromEmailaddress)
            .Property(Send.FromName, emailOperatable.FromName)
            .Property(Send.Subject, emailOperatable.Subject)
            .Property(Send.TextPart, emailOperatable.TextBody)
            .Property(Send.HtmlPart, emailOperatable.HtmlBody)
            .Property(Send.Recipients, new JArray { new JObject { { "Email", emailOperatable.ContactEmailaddress }, { "Name", emailOperatable.CreateSendToName() } } });

尝试了某事。喜欢

request.Property(Send.Attachments, "path/to/file.zip");

但这不起作用。

更新

像这样工作:

 .Property(Send.Attachments, new JArray { new JObject { { "Content-Type", "<content type>" }, { "Filename", "<file name>" }, { "content", "<base 64 encoded content>" } } });

最佳答案

似乎命名有点不同,这在 2022 年使用 API v3 对我有用

注意一些字母的大写(或缺少字母...)! 注意:内容字段是base64编码的文件数据。

.Property(
                    Send.Attachments,
                    new JArray {
                      new JObject {
                           {"Content-type", "text/plain"},
                           {"Filename", "test.txt"},
                           {"content", "VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK"}
                      }
                    }
                )

关于C# Mailjet SDK : Adding attachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46054183/

相关文章:

c# - 如何分发应用程序

c# - 使用 LINQ 进行 ASP MVC 分页?

c# - 关于 base..ctor() 的解释

iphone - 应用程序刚刚批准在 iPad 上崩溃

android - 找不到SDK和AVD Manager

java - 电子邮件中的 itext PDF 附件

C# 字符串中字符的第三个索引

android - CountDownTimer 不会让我调用 onDestroy

c# - 英雄卡图像附件未加载

ruby-on-rails - 如何获取基本网址(例如,http ://localhost:3000) of my Rails app?