0

I tried with and without HTML href tag, but gmail is taking 2-3 hours to reach recipient(to) having 2 links in a email-body. And if I send only one link in a body it will reach immediately. Googled but not getting the proper solution or hint. Can anyone help me.. here is my code and email-body:

public int sendMail(String subject, String body, String to)
  {
    MimeMessage message = this.mailSender.createMimeMessage();
    System.out.println("Welcome to sender.......");
    try
    {
      MimeMessageHelper helper = new MimeMessageHelper(message, true);      
      helper.setTo(to);
 //   helper.setFrom("reddy@abc.com");
      helper.setSubject(subject);
      helper.setText(body, true);
      this.mailSender.send(message);
      return 1;
    }
    catch (MessagingException e1)
    {
      e1.printStackTrace();
    }
    return -1;
  }

email -body:

body = "Dear " + candidate + ",<br/><b>Greetings</b><br/>link <a href='http://test.com'></a> <br/><a href='https://google.com'></a>";

how to optimize sending this type of emails?

Or any other way to send multiple links in a body?

User
  • 89
  • 2
  • 13

1 Answers1

0

Did you try setting the text in HTML format ? You need to do it on MimeMessage.

MimeMessage message = this.mailSender.createMimeMessage();

// Set From: header field of the header.
message.setFrom(new InternetAddress(from));

// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

// Set Subject: header field
message.setSubject("This is the Subject Line!");

// Now set the actual message
message.setText(body, "UTF-8", "html");
Fazie
  • 67
  • 6
  • supported method is not there.. I am getting this error:The method setText(String, String) in the type MimeMessageHelper is not applicable for the arguments (String, String, String) – User Jun 14 '18 at 08:43
  • It's because the method is on MimeMessage and not on MimeMessageHelper. Take a look at this : https://stackoverflow.com/questions/5223079/how-to-send-html-email – Fazie Jun 14 '18 at 08:50