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

Add convenience methods for replying to and forwarding emails #107

Closed
lacivert opened this issue Oct 20, 2017 · 6 comments
Closed

Add convenience methods for replying to and forwarding emails #107

lacivert opened this issue Oct 20, 2017 · 6 comments

Comments

@lacivert
Copy link

lacivert commented Oct 20, 2017

Is there a feature like reply for a specific Message object?

I have an IMAP connection and I can read mails, so I have a Message object. How can I reply to this message by using simple-java-mail?

@bbottema
Copy link
Owner

bbottema commented Oct 21, 2017

Hello @lacivert, you can do a couple of things. but really all you need is the subject and replyToAddress, or when missing the fromAddress.

Either you get it directly from the Message object (I'm assuming you mean MimeMessage) or you can convert the MimeMessage to an Email object and then easily get the required infomation:

Email fromEmail = EmailConverter.mimeMessageToEmail(yourMimeMessage);
Email email = new EmailBuilder()
    .from("Your Name", "your.name@domain.com")
    .to(fromEmail.getFromRecipient().getName(), fromEmail.getFromRecipient().getAddress())
    .subject("Re: " + fromEmail.getSubject())
    .text("...") // .textHTML("...")
    .build();

However, it seems like a nice convenience method to add asReplyTo(Email) and asForwardOf(Email). I'll add it to the list, but for now you can use the above example.

@bbottema bbottema changed the title email as a reply? Add convenience methods for replying to and forwarding emails Oct 21, 2017
@bbottema bbottema added this to the 4.5.0 milestone Oct 21, 2017
@lacivert
Copy link
Author

Thank you very much. For now, as you stated, I use such a solution. But the "original message" in reply doesn't look very well. I don't know if there is a standard solution for it but my replies doesn't look collapsed when I look from Gmail. Do you have any idea about it?

@bbottema
Copy link
Owner

bbottema commented Nov 5, 2017

I guess this has something to do with all the headers used in MimeMessage.reply(). Still looking into it.

@bbottema
Copy link
Owner

bbottema commented Nov 5, 2017

I've implemented replyTo functionality in the EmailBuilder class, but there's a catch. Currently I don't include a quote of the replied-to email's body. Perhaps that should be an optional flag, but as it stands the body entirely depends on the user. I'm note sure it's even possible, since Simple Java Mail cannot determine the HTML to be used (this is highly user-specific).

Email = new EmailBuilder()
      .asReplyTo(emailOrMessage)
      .from("name@domain.com")
      .textHTML("your body with or without quote of the email")
      .build();

Now forwarding is left, which is actually a much simpler case.

bbottema added a commit that referenced this issue Nov 6, 2017
bbottema added a commit that referenced this issue Nov 12, 2017
#102: When parsing MimeMessage to Email, also include the Return-Path as bounceToAddress
#95: When parsing MimeMessage to Email, also include the Return-Receipt-To
#93: When parsing MimeMessage to Email, also include the Disposition-Notification-To
Other: Overhauled MimeMessageParser to be more useful and usable (including better exceptions)
@bbottema
Copy link
Owner

Turns out forwarding is a much more difficult case, because as opposed to replying, forwarding actually includes the original message in the MimeMultiPart structure.

However, it's working now, both replying and forwarding! Will be in the 5.0.0 release coming up soon.

@bbottema
Copy link
Owner

bbottema commented Dec 26, 2017

Released as 5.0.0.rc1-SNAPSHOT. Add OSS' snapshots repo to find it in Maven.

EmailBuilder.startingBlank()
EmailBuilder.replyingTo(email)
EmailBuilder.forwarding(email)
EmailBuilder.copying(email)

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