0
私はJavamailに苦労しています。私はZipファイルが添付された電子メールを送信しようとしています。 添付ファイルなしでメールを送信しようとするとうまくいきますが、ジップを追加するとメールは送信されなくなります。私はエラーを持っていない...添付ファイルを追加するJavamailによってメールが送信されないようにします
マイコード:
、私は多くのことをtryiedましLOGGER.info("########################### Send Email with attachement to " + destination + " Start ######################");
//Config smtp mail
Properties props = new Properties();
props.put("mail.smtp.host", getSmtpHost());
props.put("mail.smtp.socketFactory.port", getSmtpsocketFactoryPort());
props.put("mail.smtp.socketFactory.class", getSmtpsocketFactoryClass());
props.put("mail.smtp.auth", getSmtpAuth());
props.put("mail.smtp.port", getSmtpPort());
//instance Session
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(getUsername(), getPassword());
}
});
try {
//construction objet mail
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(getFromAddress()));
//Send Email to Addresse
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(destination));
message.setSubject(objet);
message.setSentDate(new Date());
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(contenu);
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
String fileName = attachementPath + attachementName;
File file = new File (fileName);
attachmentBodyPart.attachFile(file);
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
multipart.addBodyPart(attachmentBodyPart);
message.setContent(multipart);
//send Email
Transport.send(message);
LOGGER.info("########################### Send email with attachement to " + destination + " End ########################### ");
} catch (MessagingException e) {
LOGGER.error("Error when send email to " + destination);
throw new RuntimeException(e);
}
が、私は間違いxDさんに助けを
感謝を見つけるために疲れになることがあり!!
更新:jmehrensのおかげで、問題が見つかりました。私のメールサーバーは.zipを許可していません
「私がジップを追加するとメールは送信されなくなりました。」おそらくあなたはどこかで何か例外があるかもしれないと疑っています。ところで、新しいStringBuilder(attachementPath + attachementName).toString()のポイントは何ですか? –
https://stackoverflow.com/q/17097806/180100が助けてくれるかもしれません –
メールサーバーに '.zip'で終わるファイルを許可しないというポリシーがありますか?メールクライアントだけでテストしたり、拡張子の名前を変更することができます。 – jmehrens