Renderizar Hiperlinks com Estilo Personalizado

Contents
[ ]

Pode haver momentos em que você precisa gerar hiperlinks com um estilo específico com base nos requisitos da sua aplicação. Para isso, Aspose.Email fornece HyperlinkRenderingCallback. Você pode passar o HyperlinkRenderingCallback como um parâmetro de MailMessage.GetHtmlBodyText.

O seguinte trecho de código mostra como usar HyperlinkRenderingCallback para gerar hiperlinks usando seu próprio estilo personalizado.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
public static void Run()
{
string dataDir = RunExamples.GetDataDir_Email();
var fileName = dataDir + "LinksSample.eml";
MailMessage msg = MailMessage.Load(fileName);
Console.WriteLine(msg.GetHtmlBodyText(RenderHyperlinkWithHref));
Console.WriteLine(msg.GetHtmlBodyText(RenderHyperlinkWithoutHref));
}
private static string RenderHyperlinkWithHref(string source)
{
int start = source.IndexOf("href=\"") + "href=\"".Length;
int end = source.IndexOf("\"", start + "href=\"".Length);
string href = source.Substring(start, end - start);
start = source.IndexOf(">") + 1;
end = source.IndexOf("<", start);
string text = source.Substring(start, end - start);
string link = string.Format("{0}<{1}>", text, href);
return link;
}
private static string RenderHyperlinkWithoutHref(string source)
{
int start = source.IndexOf(">") + 1;
int end = source.IndexOf("<", start);
string text = source.Substring(start, end - start);
return text;
}