Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mail is being clipped even when is so small, problem with accent in vowels (a, e, i, o, u to á, é, í, ó, ú)

I'm sending an email with the JavaMailSender with html in the body like this:

 String html = "<h2>RFC INVALIDOS en México:</h2>"+
                "<h4>Se adjunta el siguiente listado de RFC inválidos al día de la fecha.</h4>" +
                "<h3>Saludos!!!</h3>";

MimeMessageHelper helper = return new MimeMessageHelper(mimeMessage, true); // some helper
            helper.setSubject(message.getSubject());
            helper.setText(html, true);

Look at the vowels, (á, é, í) in "México", "inválidos" and "día"

and the mail is sended clipped, telling me is something more to see:

Mail body

Notice the part:

...

[Mensaje recortado] Ver todo el mensaje

But if I send it without quoting the vowels:

 String html = "<h2>RFC INVALIDOS en Mexico:</h2>"+
                "<h4>Se adjunta el siguiente listado de RFC invalidos al dia de la fecha.</h4>" +
                "<h3>Saludos!!!</h3>";

**look at the vowels **Look at the vowels, (a, e, i), in "mexico", "invalidos" and "dia"****

The mail is correctly and perfectly sent.

Correct mail Body

Any clues?

like image 982
A Monad is a Monoid Avatar asked Jun 25 '19 19:06

A Monad is a Monoid


1 Answers

MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");

This is found here: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/mail/javamail/MimeMessageHelper.html

It is implemented in their example as an abstract object definition:

mailSender.send(new MimeMessagePreparator() {
   public void prepare(MimeMessage mimeMessage) throws MessagingException {
      MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // Here is where it seems the encoding can be set, through this helper class. 
//...

I've also just found something cool now looking at the api. It may even be easier for you, if, you can make your signature a small kb image resource, and send it that way. This makes you not have to worry about UTF-8 in this scenario.

message.addInline("signature.png", new ClassPathResource("img/signature.png"));

Anyway, hope this helps. Let me know if I can try to explain it better for you. (UTF-8)

like image 104
Joe Avatar answered Sep 23 '22 17:09

Joe