我在发送带有压缩文件附件的电子邮件时收到异常,有什么建议吗?
引起:javax.mail.internet.ParseException:预期' /',得到null 在javax.mail.internet.ContentType。(ContentType.java:102)at javax.mail.internet.MimeBodyPart.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;
}
答案 0 :(得分:0)
在我自己运行程序之前不能说太多,但尝试设置内容也像这样mimeBodyPart.setContent