我想通过javamail发送包含zip文件的附件。然而,在发送它抛出一个异常作为无法通过javamail发送zip文件
com.sun.mail.smtp.SMTPSendFailedException:被封锁552-5.7.0此消息,因为它的内容提出了一个潜在的552-5.7.0安全问题。
我添加MIME内容类型application/zip
但面临
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type
application/zip at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1167)
下面是我的代码片段:
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(message, "application/zip");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
File srcFile = new File(System.getProperty("user.dir")+ "/Reports/");
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(srcFile.getPath()+"/Report.zip");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("Report.zip");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
当我删除.zip扩展它工作正常,但不能与.ZIP 。
什么时候会发生?第一个错误似乎表明你的邮件服务器不喜欢zip-attachments,第二个错误是完全不同的,并且在电子邮件交给服务器之前发生。这是什么? –
@Mark Rotteveel:所有的错误都来自'Transport.send(message);'。 – biz00ka
但你应该得到一个或另一个。不是都。当你遇到一个错误时,请仔细描述另一个错误。 –