0
このメール機能は、添付ファイルとして.html、.txtなどのすべての種類のファイルに対して機能します。しかし、添付ファイルとして.zipフォルダを送信しようとすると、終了します。javaでメール機能を送信しません。添付ファイルとして.zipを送信します。
public void sendmail(){
System.out.println("started function");
String from = "[email protected]";
// Sender's email ID needs to be mentioned
String to = "[email protected]";
final String username = "amritharajeevan.77";//change accordingly
final String password = "vivekrajeevan";//change accordingly
// Assuming you are sending email through gmail.com
String host = "smtp.gmail.com";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "25");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject("Server Error");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Server"+" " +servererror+ " " +" is unreachable. Please check the logs.");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
String filename = "/Users/aricent/Desktop/amritha/seetest/May6.zip";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
System.out.println("sent start function");
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
だから私は何をすべきか分かりません。私のコードのどの部分を変更すべきか教えてください。私は.txtと.htmlファイルを試しました。それはうまく動作します。
例外はありますか?その場合は、stacktrace情報を追加してください。 – Fildor
添付ファイルのMIMEタイプを設定する必要があると思います。 zipファイルには適切である必要があります。正確なフォーマットを覚えておいてください。しかし、どこかでウェブ上で動くでしょう。 – jr593