Syntax for System.Net.Mail send mail

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I am building a message body to be sent by email, but I can't seem to
get the correct syntax for 2 lines where I am defining the <form> and
trying to pass parameters and where I am creating a hyperlink and again
trying to pass parameters to it. I have tried escaping the "s both like
this : \" and by replacing them with single quotes : ', but neither
method seems to pass the parameters, when I hover over the link I just
get an empty first parameter i.e. ?remail= Can anybody advise?

Form line :

message.Body += "<FORM name='frmReferredEmail'
action='thank_you_referred.aspx?email=' + strEmailAddress + '&remail=' +
strEmailAddressRecommended + '&rpolicy=' + strPolicyNumber + '''
method='get'>";

Hyperlink line :

message.Body += "<tr><td><font color='black' face='Arial, Helvetica,
sans-serif' style='font-size: 11px'>If you have any problems submitting
this form please click <a class=mBlue
href='http://lbm-engine.com/insure/referred_web.aspx?remail=' +
strEmailAddressRecommended + '&email=' + strEmailAddress + '&rpolicy=' +
strPolicyNumber + '''>here</a>";
 
Mike said:
I am building a message body to be sent by email, but I can't seem to
get the correct syntax for 2 lines where I am defining the <form> and
trying to pass parameters and where I am creating a hyperlink and again
trying to pass parameters to it. I have tried escaping the "s both like
this : \" and by replacing them with single quotes : ', but neither
method seems to pass the parameters, when I hover over the link I just
get an empty first parameter i.e. ?remail= Can anybody advise?

Form line :

message.Body += "<FORM name='frmReferredEmail'
action='thank_you_referred.aspx?email=' + strEmailAddress + '&remail=' +
strEmailAddressRecommended + '&rpolicy=' + strPolicyNumber + '''
method='get'>";

Hyperlink line :

message.Body += "<tr><td><font color='black' face='Arial, Helvetica,
sans-serif' style='font-size: 11px'>If you have any problems submitting
this form please click <a class=mBlue
href='http://lbm-engine.com/insure/referred_web.aspx?remail=' +
strEmailAddressRecommended + '&email=' + strEmailAddress + '&rpolicy=' +
strPolicyNumber + '''>here</a>";

You have used an apostrophe instead of a quotation mark where you try to
end the string. That means that you are ending the property in the html
code instead of the string, and the variables are not used at all to
make the string.


You should url encode the values that goes in the query string, then you
should html encode the entire property value:

string action = "thank_you_referred.aspx?email=" +
Server.UrlEncode(strEmailAddress) + "&remail=" +
Server.UrlEncode(strEmailAddressRecommended) + "&rpolicy=" +
Server.UrlEncode(strPolicyNumber)

message.Body += "<FORM name=\"frmReferredEmail\" action=\"" +
Server.HtmlEncode(action) + "\" method=\"get\">";

This will properly encode anything that you put in the strings.
 
Back
Top