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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
MaxOvrdrv2Commented:
mail.To.Add(new MailAddress(textEmailAdd.Text) );
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Walter RitzelSenior Software EngineerCommented:
mail.To = textEmailAdd.Text;
0
 
Jamie McAllister MVPSharePoint ConsultantCommented:
mail.To.Add = new MailAddress(textEmailAdd.Text);
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.