I want to generate email "draft" server side and open in the user's email client.
The use case is: generate a "complete" email with recipients, subject and body (text/html), which will then open in the user's email client (Outlook 365 and Mail on iOS) to really just be viewed and click "send" - possibly make some manual changes.
I have tested two approaches:
To generate an EML string server side, send the string to the client, who builds an .EML file (in javascript) and downloads it with FileSaver.js. It works OK on desktop but not very good in Safari on iOS (can't get the file to download and open correctly).
saveAs(new Blob([data.eml], {type: "message/rfc822 eml;charset=utf-8"}), "email.eml");
Generate the .EML file server side and send the file to the client. This works on both desktop and Safari/iOS. Unfortunately, the mail is not displayed in "draft" state, it looks like a received mail in the user's mailbox, not editable.
private Message createMessage(String to, String subject, String body) { MimeMessage message = new MimeMessage(Session.getInstance(System.getProperties())); message.setFlags(Flag.DRAFT, true); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setContent(body, "text/html"); message.setSubject(subject); return message; }
Anyone who has been in a similar situation? How have you solved it?