0

I am trying to send a html page as mail using javamail.
my html page contains a link

<a href>click here</a>

when i am sending the mail the link is showing as a plain text.what should i do? here is the code i used

MimeMessage message = new MimeMessage(mailSession);    
message.setSubject("modified html page","text/html");    
message.setHeader("Content-Type", "text/html; charset=UTF-8");    
message.setText(html, "utf-8");    
message.setContent(html, "text/html; charset=utf-8");    

please give me a suggestion.

sai kiran
  • 38
  • 1
  • 7
  • FYI [`setText`](http://grepcode.com/file/repo1.maven.org/maven2/org.apache.geronimo.specs/geronimo-javamail_1.4_spec/1.0/javax/mail/internet/MimeMessage.java#MimeMessage.setText%28java.lang.String%2Cjava.lang.String%2Cjava.lang.String%29) does nothing here. `setText` internally calls `setContent`. Try removing it, see if you get better results. – Danny Dec 17 '13 at 14:34

1 Answers1

2

Danny rightly points out setText internally calls setContent so what you are doing here is entirely redundant. Only this would be enough :-

MimeMessage message = new MimeMessage(mailSession);    
message.setSubject("modified html page","text/html");        
message.setContent(html, "text/html; charset=utf-8"); 

Also setContent internally calls

removeHeader("Content-Type");
removeHeader("Content-Transfer-Encoding");

So there is no point calling message.setHeader("Content-Type", "text/html; charset=UTF-8"); as it would be removed anyway.

See this answer on more details on how to send HTML emails

Community
  • 1
  • 1
Caadi0
  • 504
  • 8
  • 23
  • And note that how the message is displayed is up to the mail reader. Maybe your mail reader is not displaying the link because there's no value for the href attribute? – Bill Shannon Dec 17 '13 at 20:23