【发布时间】:2018-06-23 22:32:04
【问题描述】:
我正在尝试在 sendgrid 中的路径 /Users/david/Desktop/screenshot5.png 处附加一个本地文件。
Mail mail = new Mail(from, subject, to, message);
// add an attachment
Attachments attachments = new Attachments();
Base64 x = new Base64();
String encodedString = x.encodeAsString("/Users/david/Desktop/screenshot5.png");
attachments.setContent(encodedString);
attachments.setDisposition("attachment");
attachments.setFilename("screenshot5.png");
attachments.setType("image/png");
mail.addAttachments(attachments);
这样做的正确方法是什么?
【问题讨论】: