Preview an email in default mail client before sending with Java and MimeMessage

后端 未结 1 1526
眼角桃花
眼角桃花 2021-01-26 15:43

How can i send a MimeMessage to the default email client so i can preview it before sending in JavaMail?

I work at a very burocratic company and this is a MUST.

相关标签:
1条回答
  • 2021-01-26 16:04

    If the total message size is small and plain text you can call MimeMessage.saveChanges then call all of the get methods build a URI from the existing MimeMessage. Then use the java.awt.Desktop.mail(URI) method to launch email client.

    Otherwise, you have to 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.

    0 讨论(0)
提交回复
热议问题