Free Support Forum - aspose.com

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 = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
MailMessage(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“from@domain.com”
,
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:green”>“to@domain.com”
);

mail.setSubject(
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“Subject”
);

mail.setHtmlBody(
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>"

<a href=<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>"
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>http://www.google.com.
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>"
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>>Visit Google for
searching

");

mail.save(
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“draft.msg”
,SaveOptions.getDefaultMsgUnicode());<o:p></o:p>

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.