我正在使用官方 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/