URL disappeared using MailMessage.HtmlBodyText


#1

Hello Aspose,

I found URL links disappeared from text strings by using MailMessage.HtmlBodyText in Aspose.Email for .Net 19.8. I checked several versions, and the result is the following.

[Example1]
original body:

CLICK HERE!!

converted text strings in v17.11

CLICK HERE!!http://example.com/

-> Good!

converted text strings in v18.11

CLICK HERE!!http://example.com/

-> Good!

converted text strings in v19.8

CLICK HERE!!

-> Bad. URL disappeared.

[Example2]
original body:

http://example.com/

-> the URL and the anchor text are same.

converted text strings in v17.11

http://example.com/

-> Good!

converted text strings in v18.11

http://example.com/http://example.com/

-> Bad. Outlook regards these hole strings (http://…com/>) as a URL.

converted text strings in v19.8

http://example.com/

-> Good!

I want the same behavior as v17.11.

Thank you.

sample_eml.zip (1.2 KB)


#2

@yhashimoto002,

I have tried understanding the issue on my end and have not been able to completely understand your requirement. Can you please share the working sample example code along with output (generated using old version which is correct) and output using latest version. We will investigate the issue further on our end on provision of requested information.


#3

Hello Support,

Try this code and you can get text strings converted from HTML body.

MailMessage mailMessage = MailMessage.Load(dataDir + "sample.eml", new EmlLoadOptions());
Console.WriteLine(mailMessage.HtmlBodyText);

If you try this in the above versions by using files I attached, you would find what I meant.

Thank you.


#4

Hello Support,

Sorry for forgetting print outputs.

[sample.eml]
– source
<a href="http://example.com/">CLICK HERE!!</a>
– v17.11
CLICK HERE!!<http://example.com/>
– v18.11
CLICK HERE!!<http://example.com/>
– v19.8
CLICK HERE!!

[sample2.eml]
– source
<a href="http://example.com/">http://example.com/</a>
– v17.11
http://example.com/
– v18.11
http://example.com/<http://example.com/>
– v19.8
http://example.com/

Thank you.


#5

@yhashimoto002,

I have worked with the sample code. An issue with ID EMAILNET-39594 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.


#6

I found from the documents that a GetHtmlBodyText method having a boolean parameter makes me select to extract URLs in an HTML body or not. However, when the anchor text and the URL are the same strings, I want to output only anchor text. Or, if I can put a space between the anchor text and the URL, it is also acceptable. How can I make it?

The anchor text and the URL are the following:

<a href="http://example.com/">CLICK ME!!</a>
<a href="http://example.com/">http://example.com/</a>

I’d like to output like the following:

CLICK ME!!<http://example.com/>
http://example.com/

or

CLICK ME!! <http://example.com/>
http://example.com/ <http://example.com/>

Thank you.


#7

@yhashimoto002,

We have investigated this on our end. I have shared sample code with you. This will help you to achieve desire result. Please check following sample code and share feedback with us if there is still an issue.

public void EMAILNET_39594()
{
var fileName = Path.Combine(TestUtil.GetTestPath(“EMAILNET_39594”), “sample.eml”);
MailMessage msg = MailMessage.Load(fileName);
string s1 = msg.GetHtmlBodyText(HyperlinkRendering);

        fileName = Path.Combine(TestUtil.GetTestPath("EMAILNET_39594"), "sample2.eml");
        msg = MailMessage.Load(fileName);
        string s2 = msg.GetHtmlBodyText(HyperlinkRendering);
    }

    private string HyperlinkRendering(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);
        if(Uri.IsWellFormedUriString(text, UriKind.RelativeOrAbsolute))
        {
            return string.Format("{0}", text);
        }
        else
        {
            return string.Format("{0}<{1}>", text, href);
        }
    }

#8

Thank you for your kind support. Your code is close similar to what I want.
BTY, I’m glad if the document would be updated including the way of using the GetHtmlBodyText method having a HyperlinkRenderingCallback parameter.

Thank you.


#9

@yhashimoto002,

Thanks for contacting us. We are investigating this and will get back to you with feedback soon.