Saturday, 21 March 2015

ASP.NET - MailTo - Code behind example with body that has link to some html page with "?"

Watch this example on YouTube:

MailTo example with body that has html link in it - how to fix question mark issue:


Replace
string url = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "?argument=Number1";
            string command = "mailto:test@test.com?subject=title&body=click this link: " + url ;
            System.Diagnostics.Process.Start(command);

with

string url = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "%26argument=Number1";
            string command = "mailto:test@test.com?subject=title&body=click this link: " + url ;
            System.Diagnostics.Process.Start(command);

Explanation - some mail clients will remove part of the link just after "?" ?argument=Number1

No comments:

Post a Comment