Mail sending in c#

Aug 30 2008 9:58 AM
hi I have an application where I need to send a mail. I tried in this way

 

SmtpClient smtp = new SmtpClient();

MailMessage mail = new MailMessage();

mail.From = new MailAddress(txtFrom.Text);

smtp.Credentials = new NetworkCredential("User Id", "Password");

mail.To.Add(txtTo.Text);

mail.Subject = "Mail Sending";

mail.Body = rtxtBody.Text;

smtp.Host = "smtp.gmail.com";

smtp.Port = 25;

smtp.EnableSsl = true;

 

smtp.Send(mail);

MessageBox.Show("Mail sent succesfully");

 

With this I am getting the mail sent to the user id given in credentials. But I need the mail to be send to the address entered by the user in the from text box. I am getting mail sent to 'To' address correctly. But this is the problem with from. Can you please help me?

 

And also when we reply to the mail sent, the to address should be the address address by the first user in default. I think I can get this with mail send to the address entered by the user.


Answers (3)