1
 Dim x As String
 x = "http://www.domain.com/aaa/test/default2.aspx?date=" & now.Text & "&tfname=" & p1fname.Text & "&tlname=" & p1lname.Text & "&comp=" & Request.QueryString("comp")

 Dim objEmail As New MailMessage()
 objEmail.To = "[email protected]"
 objEmail.From = "[email protected]"
 objEmail.Cc = "[email protected]"
 objEmail.Subject = "Test Email"
 objEmail.Body = x
 SmtpMail.SmtpServer = "mail.domain.com"
 Try
     SmtpMail.Send(objEmail)
 Catch exc As Exception
     Response.Write("Send failure: " + exc.ToString())
 End Try

When I get the email it comes with

http://www.domain.com/aaa/test/default2.aspx?date=1/13/2011

as a link

and the rest as text

11:39:09 AM&tfname=sadasd&tlname=asd&comp=GWI

2 Answers 2

3

Whenever you put a parameter into a query string, you should encode it using System.Web.HttpUtility.UrlEncode to avoid invalid characters going into the URL:

x = "http://www.domain.com/aaa/test/default2.aspx?date=" & HttpUtility.UrlEncode(now.Text) &
    "&tfname=" & HttpUtility.UrlEncode(p1fname.Text) &
    "&tlname=" & HttpUtility.UrlEncode(p1lname.Text) &
    "&comp=" & HttpUtility.UrlEncode(Request.QueryString("comp"))
Sign up to request clarification or add additional context in comments.

Comments

2

You cannot have Spaces in the query string, if you need to put spaces, replace it with %20 before appending to the querystring. Although the ideal way to do this is to encrypt and decrpt the text in the querystring.

5 Comments

@MyHeadHurts the reason you see it as a link, is because gmail was smart enough to convert it for you. Because you have a space in it, google couldn't figure out where it ended. If you'd like to send it as a real link, use an anchor.
well for the date i am using datetime.now how can i format it to be a date and time with no spaces
@MyHeadHurts System.Web.HttpUtility.UrlEncode(DateTime.Now.ToString())
@MyHeadHurts But just so you're aware, not every email tool will show that as a link. Most will just show it as text.
You can use the ToString override of the DateTime to provide a format for your date time, you can always just get the date part of the whole date and time with like a "-" inbetween rather than space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.