我试图使用javamail附加一个zip文件,并得到以下错误:
Com.sun.mail.smtp.SMTPSendFailedException: 552-5.7.0此消息被阻止,因为其内容可能存在552-5.7.0安全问题。请访问http://support.google.com/mail/bin/answe 552-5.7.0 r.py?answer=6590查看我们的邮件内容和附件内容552 5.7.0指南。vb7sm60966875pbc.13 -gsmtp。
附加文档或xls没有任何问题。我甚至认为附加一个zip文件和任何其他文件没有什么不同。请告诉我这里有什么问题。
如果需要的话,我也提供了代码。
public class SendMail {
@Test
public static void sendFileEmail()
{
// Recipient's email ID needs to be mentioned.
String to = "*****@gmail.com";
// Sender's email ID needs to be mentioned
String from = "****@gmail.com";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "465");
properties.put("mail.debug", "false");
// Get the default Session object.
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("*****@gmail.com","****");
}
});
try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));
// Set Subject: header field
message.setSubject("This is the Subject Line!");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("This is message body");
// Create a multipar message
Multipart multipart = new MimeMultipart();
// Set text message part
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String filename = "XSLTReports.zip";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Send the complete message parts
message.setContent(multipart);
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}发布于 2014-03-19 11:46:34
我认为这个问题与zip文件的内容有多大的关系。我更改了压缩文件,它运行良好。
发布于 2014-03-19 11:18:40
我想您还没有为您发送的多部分攻击设置MIME类型。尝试设置它并查看
ZIP文件的标准MIME类型是application/zip。
如果应用程序/八位流不起作用,也可以尝试它
发布于 2014-03-19 12:46:07
请确保网络访问是正常的,问题似乎首先是网络访问权限:尝试从您的计算机到邮件服务器的ping (如果可以的话,它可以访问)第二:尝试发送简单的邮件(主题/内容)第三:尝试附加简单的doc (txt文件)
https://stackoverflow.com/questions/22503893
复制相似问题