Alex Rivera | Logout

Why do I get "'property cannot be assigned" when sending an SMTP email?

Asked 2012-02-08T20:54:00.230
278

I can't understand why this code is not working. I get an error saying property can not be assigned

MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
mail.To = "user@hotmail.com"; // <-- this one
mail.From = "you@yourcompany.example";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
Edit
Report

1 Answer

261

This :

mail.To = "user@hotmail.com";

Should be:

mail.To.Add(new MailAddress("user@hotmail.com"));
answered 2012-02-08T20:57:58.847

Your Answer