我試圖使用JavaMail附加一個zip文件附加zip文件,並提示以下錯誤:問題在JavaMail的
「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();
}
}
}
我相信問題是一些如何與zip文件的內容有關。我改變了zip文件,它工作正常。感謝您的答覆 ! – Siv