本文介绍了Java电子邮件中HTML格式的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
try{
String msg="Happy BirthDay Dear,<b> "+name.toUpperCase()+" </b> !!! Have a Great Day. \n \n Thank You \n Seva Development ";
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setTo(email);
helper.setText(msg);
helper.setSubject("BirthDay");
mailSender.send(message);
}catch (Exception e){}
}
我正在尝试加粗用户的名称,但它显示在邮件中,如图所示。思想或解决方案受到高度赞赏
I am trying to bold the name of the user but it displays as it is in the mail as shown in the picture. Ideas or solutions are highly appreciated
推荐答案
这对我有用,我有更改了两个行代码,谢谢大家的贡献
This worked for me, I have changed two line code, Thank you all for your contribution
private void sendEmail(String email,String name) throws Exception{
Thread thread=new Thread(){
@Override
public void run() {
try{
String msg="Dear<b> "+name.toUpperCase()+" </b>,<p> On Behalf of someone we would like to wish you a Many many Happy returns of the day</p> <p style=color:red;>Happy Birthday and Have a Great Day.</p>\n \n Thank You!";
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message,true);
helper.setTo(email);
helper.setText(msg);
message.setContent(msg, "text/html");
helper.setSubject("BirthDay");
mailSender.send(message);
}catch (Exception e){}
}
};
thread.start();
}
这篇关于Java电子邮件中HTML格式的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!