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

瘦欲@ 提交于 2019-12-04 05:41:11

问题


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:


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.



来源:https://stackoverflow.com/questions/25449712/preview-an-email-in-default-mail-client-before-sending-with-java-and-mimemessage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!