通过 smtp 发送到 iphone 的电子邮件附件在 iphone 本机电子邮件应用程序中不可见
Email attachment sent via smtp to iphone are not visible in iphone native email app
我有一个网络服务可以发送带附件的电子邮件。
发送邮件的代码片段是
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 电子邮件应用程序中,我无法查看附件。
在图片中,我们可以看到附件图标,但是当我打开邮件时,我找不到附件
我还提到了 link:
https://discussions.apple.com/thread/7491137?start=30&tstart=0
是否有针对此的编程解决方案?
您附加 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);
我有一个网络服务可以发送带附件的电子邮件。
发送邮件的代码片段是
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 电子邮件应用程序中,我无法查看附件。
在图片中,我们可以看到附件图标,但是当我打开邮件时,我找不到附件 我还提到了 link: https://discussions.apple.com/thread/7491137?start=30&tstart=0
是否有针对此的编程解决方案?
您附加 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);