HTML format using Java mail in android
Posted
by
TheDevMan
on Stack Overflow
See other posts from Stack Overflow
or by TheDevMan
Published on 2014-06-07T03:17:54Z
Indexed on
2014/06/07
3:25 UTC
Read the original article
Hit count: 159
I am trying to implement an HTML format mail using the Java mail in android. I would like to get results like this:
When I look at the html format sent from lookout in my GMAIL. I don't see any link, but just has this format:
[image: Lookout_logo]
[image: Signal_flare_icon] Your battery level is really low, so we located
your device with Signal Flare.
I was trying the following:
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true"); // added this line
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
javax.mail.Session session = javax.mail.Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for( int i=0; i < to.length; i++ )
{
// changed from a while loop
toAddress[i] = new InternetAddress(to[i]);
}
message.setRecipients(Message.RecipientType.BCC, toAddress);
message.setSubject(sub);
//message.setText(body);
body = "<!DOCTYPE html><html><body><img src=\"http://en.wikipedia.org/wiki/Krka_National_Park#mediaviewer/File:Krk_waterfalls.jpg\">";
message.setContent(body, "text/html; charset=utf-8");
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
When I look at the html format sent with the above code. I get the following:
<!DOCTYPE html><html><body><img src="http://en.wikipedia.org/wiki/Krka_National_Park#mediaviewer/File:Krk_waterfalls.jpg>
How to make sure the user will not be able to see any html code or URL link like the mail sent by LOOKOUT?
Thanks!
© Stack Overflow or respective owner