Click here to Skip to main content
15,885,546 members

sending email using localhost

Revision 3
Hi,

In my website I am sending email from localhost.
If I specify the email address to which I would like to send email it succeed, but I would like to retreive the toAddress from the text box control.
If i do this it gives the error:
""The specified string is not in the form required for an e-mail address.""


The code to send a email looks like this:
C#
var fromAddress = new MailAddress("myid@gmail.com", "sarwar");
var toAddress = new MailAddress("to@gmail.com","symon");// Here I would like to get value from the text box.

const string fromPassword = "password"; 
const string subject = "lokman";
const string body = "i have done it";

var smtp = new SmtpClient
           {
               Host = "smtp.gmail.com",
               Port = 587,
               EnableSsl = true,
               DeliveryMethod = SmtpDeliveryMethod.Network,
               UseDefaultCredentials = false,
               Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
           };

using (var message = new MailMessage(fromAddress, toAddress)
                     {
                         Subject = subject,
                         Body = body
                     })
try
{
    smtp.Send(message);
}
Posted 24-Dec-12 8:11am by symonsarwar.
Tags: ,