Salam, I have an application that generate time tabling in a grid pane and i could turn the gridpane to image in order to print it but now i want to send that image in email but i can't find a way I have seen similiar topics but they send image existing in computer by its path but in my case i don't want to save the image i just want to send it directly with java class Image or ImageView Here is my code
@FXML
void send_mail(ActionEvent event) throws IOException {
final String username = "******@gmail.com";
final String password = "******";
Properties props = new Properties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
javax.mail.Session session = javax.mail.Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("*****@yahoo.com"));
message.setSubject("Testing Subject");
message.setText("PFA");
MimeBodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(image, "IMAGEVIEW");
// String file = "../emploi/"+fileName;
messageBodyPart.setText("Emploi de temps");
//DataSource source = new FileDataSource(file);
// messageBodyPart.setDataHandler(new DataHandler((DataSource) file));
// messageBodyPart.attachFile(file);
messageBodyPart.setFileName("Emploi de temps");
multipart.addBodyPart(messageBodyPart);
MimeBodyPart photoBodyPart = new MimeBodyPart();
photoBodyPart = new MimeBodyPart();
photoBodyPart.setContent(image, "IMAGEVIEW");
multipart.addBodyPart(photoBodyPart);
message.setContent(multipart);
System.out.println("Sending");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
e.printStackTrace();
}
}
but i get this error
javax.mail.internet.ParseException: In Content-Type string , expected '/', got null at javax.mail.internet.ContentType.(ContentType.java:104) at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1510) at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1172) at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:522) at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1533) at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2271) at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2231) at javax.mail.Transport.send(Transport.java:123)