bbottema/simple-java-mail

When replying to an email with HTML, the result body is empty

Diegofr104 opened this issue · 10 comments

Hi, I was trying to make a reply to a email but it's sending with empty content, I tried using forward and is working fine.

Other thing when I set a flag for search answered not showing any answered messages (other answered messages answered in gmail UI are showing).

I'm declaring the mail same as says in page. I tried using plaintext(message) and same result.

Email sendMail = EmailBuilder.replyingTo(emailR)
			.from("Estancia XXI", emailE.getEmail())
			.prependText(message)
			.buildEmail();

sin titulo

Ok, so if I read you correctly, you are using replyingTo() to send a reply, but in Gmail you see and empty body for the reply?

Then when you search for answered (how do you do this?) the reply is not showing up.

Correct?

@Diegofr104, can you verify my summary?

first, you are correct i saw an empty body. when i try to saw what was sended.

for the second thing.
I get all the not answered mails in my app using java mail, then i select one from the list and reply the mail i want.
After that i move to other panel in the app that i can get the answered ones and shows empty.

If you need a little more code i can paste here so you can see better.

That would be very helpful, @Diegofr104. Especially "I get all the not answered mails in my app using java mail" I would like to understand better.

@lacivert, did you have any issues like this?

@Diegofr104

Actually, I have an idea of what is going on. Replying to a message always sets HTML content as well. But you use .prependText(), which is ignored by modern clients if HTML is present.

Try this instead:

Email sendMail = EmailBuilder.replyingTo(emailR)
			.from("Estancia XXI", emailE.getEmail())
			.prependText(message) 
			.prependTextHTML(message) // < add this line
			.buildEmail();

Or remove the HTML content completely, leaving only the text:

Email sendMail = EmailBuilder.replyingTo(emailR)
			.from("Estancia XXI", emailE.getEmail())
			.prependText(message) 
			.clearTextHTML(message) // < add this line
			.buildEmail();

I've updated the Javadoc for replyingToEmail as well.

Im having 0 time right now to test your solution,i will do tomorrow if i have some little space between work.
Thx.

Did you verify either of these suggestions solve your issue?

@bbottema not OP but think i'm facing the same issue -

In my case I've got an email with only text/html + attachment content, no text/plain.

using the below, I get a reply that does not include the original email body.

Email email = EmailBuilder.replyingTo(original)
  .clearReplyTo()
  .withReplyTo("name", "email")
  .from("name","email")
  .prependTextHTML("<div dir=\"ltr\">Origianl message should be below</div>")
  .buildEmail();

If i forward this email, it works brilliantly, but fails on reply entirely.

Not sure, but i think the issue might be line 303 of email::emailBuilder:

.withHTMLText(format(htmlTemplate, defaultTo(repliedTo.getPlainText(), "")))

which i think should read:

.withHTMLText(format(htmlTemplate, defaultTo(repliedTo.getHTMLText(), "")))

EDIT: @bbottema I've made the change I described above, and that has solved the problem. I'll send you a PR.

Fix released in 5.0.5, please confirm.