title: Sending an email to yahoo in asp.net
body: <p>I want to send email using c#. I imlemented whole code, also use port no, host in the code. but email is not received.</p>
  
  <p><strong>.aspx</strong></p>
  
  <pre><code>Message from: &lt;asp:TextBox ID="text1" runat="server"&gt;&lt;/asp:TextBox&gt;
  Message To: &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
  Message subject: &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:Button ID="b1" runat="server" OnClick="click" /&gt;
  &lt;asp:Label ID="Label1" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p><strong>.aspx.cs</strong></p>
  
  <pre><code>public void click(object sender, EventArgs e)
  {
      try
      {
          //mail message
          MailMessage mM = new MailMessage();
          //Mail Address
          mM.From = new MailAddress( text1.Text);
          //emailid to send
          mM.To.Add(TextBox1.Text);
          //your subject line of the message
          mM.Subject = "your subject line will go here.";
          //now attached the file
          //mM.Attachments.Add(new Attachment(@"C:\\attachedfile.jpg"));
          //add the body of the email
          mM.Body = "Your Body of the email.";
          mM.IsBodyHtml = false;
          //SMTP 
          SmtpClient SmtpServer = new SmtpClient();
          //your credential will go here
          SmtpServer.Credentials = new System.Net.NetworkCredential("sender@yahoo.com", "password");
          //port number to login yahoo server
          SmtpServer.Port = 587;
          //yahoo host name
          SmtpServer.Host = "smtp.mail.yahoo.com";
          SmtpServer.Send(mM);
          Label1.Text = "successfull";
          //Send the email
  
      }//end of try block
      catch (Exception ex)
      {
      }//end of catch
  }//end of Yahoo Email Method
  </code></pre>