Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is my code which i used so far.
It sends mail but i am not receiving mail.
Please help.




protected void Button1_Click(object sender, EventArgs e)
{
  SmtpClient smtpclient = new SmtpClient();

  MailMessage message = new MailMessage();

  smtpclient.Host = "smtp.gmail.com";
  smtpclient.Port = 587;

  try
  {
    MailAddress SendFrom = new MailAddress(T1.Text);
    MailAddress SendTo = new MailAddress(T2.Text);
    MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
    MyMessage.Subject = T3.Text;
    MyMessage.Body =T4.Text;
    T5.Text = "Message Sent";
  }
  catch (Exception ex)
  {
    T5.Text = ex.ToString();
  }
}
Posted
Updated 30-Mar-11 4:37am
v2

1 solution

Nowhere in this code are you actually sending the email. That's a function of the SmtpClient object.

Here's info on the SmtpClient.Send(MailMessage) method.[^]

To send the message from your code, you'd need the line smtpclient.Send(message). I don't know if there's any further configuration you'll need to do on your SmtpClient object before you do this, but it'll get you headed in the right direction.
 
Share this answer
 
v3
Comments
chetanp322 30-Mar-11 10:53am    
Can you plz Provide me code for that
Marc A. Brown 30-Mar-11 11:04am    
I've updated my solution. I'd recommend that, instead of asking for code so quickly, you do a quick google search in the future when you get an answer pointing you in the right direction. That's what I did to answer your question (I saw what was wrong, but wanted to be sure I gave you accurate info on how to fix it).
If my solution helps you, don't forget to accept it as the correct answer!
Have a great day!
#realJSOP 30-Mar-11 11:37am    
Proposed as solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900