I have an ASP.NET 4.0 aspx page from which I wish to send an email to the recipient specified in a text box named “supervisoremailTextBox”. Is there any way that I can specify a variable as the recipient email address. The code I have used which doesn’t work is shown below:
MailAddress fromAddress = new MailAddress("address@domain.co.uk", "Sender Name");
MailAddress toAddress = new MailAddress("supervisoremailTextBox.Value");
message.From = fromAddress;
message.To.Add(toAddress);
Sorry if this a really dumb question and thanks in advance for your help.
When you use
MailAddress, you need to use a valid email address.The string
"supervisoremailTextBox.Value"is not a valid email address.If you mean to use the value of a textbox with the ID
supervisoremailTextBox, use:Note that I have dropped the
"to ensure you are not passing in a string.