Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Java Mail from MimeMessage #22

Closed
neil-ceschi opened this issue Sep 15, 2015 · 5 comments
Closed

Simple Java Mail from MimeMessage #22

neil-ceschi opened this issue Sep 15, 2015 · 5 comments

Comments

@neil-ceschi
Copy link

I would need to handle files saved in .eml format, easily convertible into MimeMessage. It would be great to build SimpleMail from MimeMessage!
Thanks a lot!

@bbottema
Copy link
Owner

If you provide an implementation or piece of code that fills an Email instance completely using a MimeMessage, I will integrate it into Simple Email.

@bbottema
Copy link
Owner

The truth is, MimeMessage is a ambiguous type tree structure. The Email class works exactly why MimeMessage doesn't: it has a simple interface and it allows you do define an email in exactly one way. MimeMessage on the other hand is a messy heap of recursive nonsense and extracting data from that is a lot harder than putting data into it.

@bbottema
Copy link
Owner

On the other hand, Apache seems to have an implementation already. I might just use some of that.

@bbottema
Copy link
Owner

@neil-ceschi, I implemented a MimeMessage parser based on Apache's version. I had to modify a few a few things: headers were not parsed in Apache's version and attachments and embedded images were not properly distinguished (they ignored Part.INLINE and Part.ATTACHMENT predispositions).

I'll release a new version somewhere this week when I have the time. Releasing always takes me more time than implementing an actual fix :/

Usage:

Email email = new Email(yourMimeMessage);
// the other way around is now possible too!
MimeMessage mimeMessage = Mailer.produceMimeMessage(yourEmail, yourSession /* or null */);

The following should be true then:

Email emailSource = new Email();
/* populate email... */
Email emailTarget = new Email(mailer.produceMimeMessage(emailSource, null));

emailSource.equals(emailTarget);

bbottema referenced this issue Feb 24, 2016
…essage))

2. exposed produceMimeMessage in Mailer, so you can play with that too
3. added toString support for Recipient
@bbottema
Copy link
Owner

Release in v3.0.0!

Demo included in MailTest.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants