views:

136

answers:

2

Hi

Basic question here: I'm sending emails using the default SmtpClient of the .NET framework (3.5). The bodytype is HTML (IsBodyHtml = true) In the body I've added a url with two parameters in the querystring like so:

http://server.com/page.aspx?var1=foo&var2=bar

This get's encoded to:

http://server.com/page.aspx?var1=foo%26var2=bar (the ampersand is encoded as percent-26)

When doing a simple Request["var2"] I get 'null'. What should I do to properly encode the ampersand in the mail message?

A: 

Use the UrlEncode method. This will do all the encoding of your input string for you.

Gerrie Schenck
+2  A: 

This works fine for me:

var client = new SmtpClient();
client.Host = "smtp.somehost.com";
var message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.IsBodyHtml = true;
message.Subject = "test";
string url = HttpUtility.HtmlEncode("http://server.com/page.aspx?var1=foo&var2=bar");
message.Body = "<html><body><a href=\"" + url + "\">Test</a></body></html>";
client.Send(message);
Darin Dimitrov
Alright. It appears that Outlook Web Access is mangling the URL, not the SmtpClient or anything :( Problem solved
edosoft