Skip to content

Mail sending in c#

Ram Reddy Mekha

Asked Aug 30, 2008, 5:58 AM EDT3 answers
Share
LinkedInX
hi I have an application where I need to send a mail. I tried in this way

 

VB.NET
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.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Hi there, it would be helpful if you could provide us with some more details, is the application in what form ,by that i mean is it asp.net and if it is , which version 

    regards

    0
  • 0
    No, it's a winforms application where I need to send a mail. And I tried as said above. But with that a mail is sent with from address as the address given in credentials where as I want to send a mail with an id given by the user to an id given by the user itself. And then if the received user clicks on reply then the composer should open as in the normal case with to address as the address from whom he got the mail.
    0