首页 > 解决方案 > 您将如何使用 MailJet api 附加 excel 文档

问题描述

您好,我尝试使用 mailjets api 发送 excel 文档。我首先使用 mailjets 库将 excel 文件编码为 base64。然后我使用 mailjets 库将文件添加为附件并设置 mime 类型 application/vnd.ms-excel。这是一个例子。

 request = new MailjetRequest(Emailv31.resource)
            .property(Emailv31.MESSAGES, new JSONArray()
                .put(new JSONObject()
                    .put(Emailv31.Message.FROM, new JSONObject()
                        .put("Email", "pilot@mailjet.com")
                        .put("Name", "Mailjet Pilot"))
                    .put(Emailv31.Message.TO, new JSONArray()
                        .put(new JSONObject()
                            .put("Email", "passenger1@mailjet.com")
                            .put("Name", "passenger 1")))
                    .put(Emailv31.Message.SUBJECT, "Your email flight plan!")
                    .put(Emailv31.Message.TEXTPART, "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!")
                    .put(Emailv31.Message.HTMLPART, "<h3>Dear passenger 1, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!")
                    .put(Emailv31.Message.ATTACHMENTS, new JSONArray()
                        .put(new JSONObject()
                            .put("ContentType", "application/vnd.ms-excel")
                            .put("Filename", "test.txt")
                            .put("Base64Content", "excelFileBase64")))));
      response = client.post(request);

但是,我总是收到文件,因为它的字符串表示 base64 编码。

标签: emailmailjet

解决方案


推荐阅读