Draft email message with hyperlinks

Hi,


I’m trying to create a Draft email message with hyperlinks.
I use the following API:

message.setSubject(subject);

message.setBody(messageBody);

message.getHeaders().add("X-Unsent", "1");


And the messageBody is "aaa http://www.google.com, bbb http://www.something.com"

Unfortunately when I open such a draft message in Outlook the hyperlinks are not working (are not in blue and not clickable). Is there any way to make the links clickable in the draft message?


Thank you,

Mariusz

Hi Mariusz,

Thank you for contacting Aspose support team.

You may please use setHtmlBody() to set the html body of the message. Please give a try to the following sample code and let us know the feedback.

MailMessage mail = new MailMessage("from@domain.com", "to@domain.com");
mail.setSubject("Subject");
mail.setHtmlBody("<a href=\"http://www.google.com\">Visit Google for searching</a>");
mail.save("draft.msg", SaveOptions.getDefaultMsgUnicode());

Thanks, I used the code below to change the text body to HTML:


String htmlBody = StringEscapeUtils.escapeHtml(messageBody);


htmlBody = htmlBody.replaceAll("\n", " \n");

htmlBody = htmlBody.replaceAll("(\\A|\\s)((http|https|ftp|mailto):\\S+)(\\s|\\z)", "$1$2$4");

htmlBody = htmlBody.replaceAll("\n", "
"
);


message.setHtmlBody("

" + htmlBody + "

");


Thanks,

Mariusz

Hi Mariusz,


Could you please be a little more specific and provide us the finalized HTML content that is to be set as the message’s html body? This will help us reproduce the issue at our end for assisting you further. It would be of further help if you could provide us with the sample message file as well.