Spring - 在email-body中有多个链接的java邮件

时间:2018-06-14 08:35:08

标签: html spring gmail javamail

我尝试使用和不使用HTML href标签,但gmail需要2-3个小时才能到达收件人(到)在电子邮件正文中有2个链接。如果我只在身体中发送一个链接,它将立即到达。谷歌搜索但没有得到正确的解决方案或暗示。 谁能帮我.. 这是我的代码和电子邮件正文:

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>";

如何优化发送此类电子邮件?

或者在身体中发送多个链接的任何其他方式?

1 个答案:

答案 0 :(得分:0)

您是否尝试以HTML格式设置文字?您需要在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");