Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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

0
devnewbee
Asked:
devnewbee
  • 2
  • 2
  • 2
  • +1
1 Solution
 
MaxOvrdrv2Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
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.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now