發送帶有壓縮文件附件的電子郵件時出現異常,有什麼建議嗎?在 javax.mail.internet.MimeBodyPart預計 '/',在javax.mail.internet.ContentType了空 (ContentType.java:102):發送帶有zip文件附件的電子郵件時發生ParseException?
造成的:javax.mail.internet.ParseException。 .updateHeaders(MimeBodyPart.java:1322) 在 javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1021) 在 javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:419) 在 javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:13
private MimeBodyPart makeZipAttachment(AttachmentInfo attachmentInfo) throws IOException, MessagingException {
ByteArrayOutputStream bos = null;
ZipOutputStream zip = null;
try
{
bos = new ByteArrayOutputStream();
zip = new ZipOutputStream(bos);
zip.putNextEntry(new ZipEntry(attachmentInfo.getName()));
InputStream inputStream = attachmentInfo.getAttachment().getInputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
zip.write(buffer, 0, len);
}
zip.closeEntry();
}
finally
{
if (bos != null)
bos.close();
if (zip != null)
zip.close();
}
DataSource dataSource = new ByteArrayDataSource(bos.toByteArray(), "application/zip");
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
mimeBodyPart.setFileName(attachmentInfo.getName() + ".zip");
mimeBodyPart.setHeader(CONTENT_TYPE, "application/zip");
return mimeBodyPart;
}
這是否幫助? https://stackoverflow.com/questions/40985782/javax-mail-internet-parseexception-in-content-type-string-text-expected – Kon