I was trying to send a file using mail but I wanted to first it open in a draft mail like mailto in jsp. I had implemented mail to functionality in Java but I am not able to attach file to opened mail. other are working file except the attachment. here is my code:
public static void mailto(List<String> recipients, String subject,
String body) throws IOException, URISyntaxException {
String uriStr = String.format("mailto:%s?subject=%s&body=%s",
recipients,subject,body);
Desktop.getDesktop().browse(new URI(uriStr));
}
can any one suggest me how to attach file using mailto or any other api that can useful for me.enter code here
thanks in advance.
Create Multipart MimeMessage using JavaMail but instead sending it call MimeMessage.saveChanges then use MimeMessage.writeTo to save it to the filesystem as '.eml'. Then open that file with java.awt.Desktop.open to launch the email client. You'll have to handle clean up after the email client is closed.
You also have to think about the security implications of email messages being left on the file system.