I'm using a table (Table has the location and mail id's) to get the e-mail id based on which location we are selecting.
Trying to send the mail gives the following error:
The specified string is not in the form required for an e-mail address.
Code:
public void sendmail()
{
SqlCommand cmd = new SqlCommand("select EmailID from Table where Location='"+Location.Text+"'",con);
cmd.ExecuteNonQuery();
string EmpMail = "Test@gmail.com";
string EmpMailTo = "cmd";
MailMessage message = new MailMessage(EmpMail, EmpMailTo);
SmtpClient client = new SmtpClient();
message.Subject = "Auto generated mail";
message.IsBodyHtml = true;
message.Body = "Test mail for auto generation";
client.Host = "Apprelay";
client.Send(message);
}
Can anyone please help me to fix this? Thanks in advance.