How can I make the value of my "mailaddress to" the value of a textbox?

This will not work. ( mail.To.Add = textEmailAdd.Text;)

What am I doing wrong?
MailMessage mail = new MailMessage();
                mail.From = new MailAddress("do-not-reply@test.com");
                mail.To.Add = textEmailAdd.Text;
                mail.Subject = "Test E-Mail";
                mail.Body = html;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient("test.smtp.com");
                smtp.Send(mail);

Open in new window

devnewbeeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MaxOvrdrv2Connect With a Mentor Commented:
mail.To.Add(new MailAddress(textEmailAdd.Text) );
0
 
Walter RitzelSenior Software EngineerCommented:
mail.To = textEmailAdd.Text;
0
 
Jamie McAllister MVPSharePoint ConsultantCommented:
mail.To.Add = new MailAddress(textEmailAdd.Text);
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
devnewbeeAuthor Commented:
Thanks so much.  I appreciate your help.
0
 
devnewbeeAuthor Commented:
Thanks to everyone.
0
 
MaxOvrdrv2Commented:
sorry wp and Jaime... but for future if anyone asks this, the Add option of the MailMessage object is a function... so you have to call it as such, and it takes a MailAddress var ...

cheers!
0
 
Walter RitzelSenior Software EngineerCommented:
Well,
my mistake is think of on the deprecated System.We.Mail namespace.... I look into an old code of mine...
0
All Courses

From novice to tech pro — start learning today.