我有一个发送带附件的电子邮件的网络服务。
发送电子邮件的代码段是
MimeMultipart content = new MimeMultipart("related");
msg.setContent(content);
MimeBodyPart attachment = new MimeBodyPart();
File file = new File("filename.txt");
String fileName = "";
DataSource fds;
String fullPathFile = mail.getAttachment().get(i);
String pathArray[] = fullPathFile.split("/");
fds = new FileDataSource(file);
attachment.setDataHandler(new DataHandler(fds));
attachment.setHeader("Content-ID", "<" + id + ">");
attachment.setFileName(fds.getName());
content.addBodyPart(attachment);
这适用于每个电子邮件应用。但在本机iPhone电子邮件应用程序中,我无法查看附件。
在图片中,我们可以看到附件图标,但是当我打开电子邮件时,我找不到附件 我还提到了这个链接: https://discussions.apple.com/thread/7491137?start=30&tstart=0
是否有针对此的编程解决方案?
答案 0 :(得分:1)
您附加MimeBodyPart的方式导致了此问题。我有同样的问题。您的修补程序如下所示:
attachments = new MimeBodyPart();
DataSource source = new FileDataSource(dest);
attachments.setDataHandler(new DataHandler(source));
attachments.setFileName(source.getName());
mp.addBodyPart(attachments);
Multipart htmlAndTextMultipart = new MimeMultipart("alternative");
MimeBodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent(body, "text/html; charset=utf-8");
htmlAndTextMultipart.addBodyPart(htmlBodyPart);
MimeBodyPart htmlAndTextBodyPart = new MimeBodyPart();
htmlAndTextBodyPart.setContent(htmlAndTextMultipart);
mp.addBodyPart(htmlAndTextBodyPart);