Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my Design page
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table style="border:1px solid" align="center">
    <tr><td>Username:</td><td><asp:TextBox runat="server" ID="txtUsername"></td></tr>
    <tr><td>Password:</td><td><asp:TextBox runat="server" ID="txtPassword" TextMode="Password"></td></tr>
    <tr><td valign="top">Address:</td><td><asp:TextBox runat="server" ID="txtAdress" TextMode="MultiLine"></td></tr>
    <tr><td>Email-id:</td><td><asp:TextBox runat="server" ID="txtEmail"></td></tr>
    <tr><td colspan="2" align="center"><asp:Button runat="server" ID="btnRegister" 
            Text="Register" onclick="btnRegister_Click" /></td></tr>
    </table>
    
    </div>
    </form>
</body>
</html>


this is my code page
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        MailMessage msg = new MailMessage();
        msg.To.Add(txtEmail.Text);
        msg.From = new MailAddress("mysiteadmin@peers");
        msg.Subject="thanks for registraion";
        msg.Body="thanks for registraion";
        SmtpClient obj = new SmtpClient();
        obj.Host = "sri";obj.Send(msg);
        Response.Write("<h2>Registered</h2>");

    }
}



Here am getting an error below.... can u please help
C#
Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 100.64.243.189 (100.64.243.189:25), connect error 10061

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 100.64.243.189 (100.64.243.189:25), connect error 10061

Source Error: 
Line 21:         msg.Body="thanks for registraion";
Line 22:         SmtpClient obj = new SmtpClient();
Line 23:         obj.Host = "sri";obj.Send(msg);
Line 24:         Response.Write("<h2>Registered</h2>");
Line 25:
Posted
v3
Comments
Anurag Sinha V 4-Mar-13 2:43am    
Mate,

It looks that you haven't added the code for SMTP server.
May I ask what SMTP server are you using??
Also you need to configure the port number..
Kishor Deshpande 4-Mar-13 3:06am    
It's a repost.
Please post the duplicate question link.
We will delete one.

here is some problem with your smtp details please go with the below link :

ASP.Net: Send emails[^]

hope it ll solve your problem.

Thanks.
 
Share this answer
 
v2
Comments
Anurag Sinha V 4-Mar-13 2:45am    
hi,
went through ypur article on your blog.
crisp write up..cheers

regrds
anurag
nehas1jan 4-Mar-13 2:47am    
Hi,

Thanks for your nice words.
Anurag Sinha V 4-Mar-13 2:53am    
np...keep coding..

regrds
anurag
There may be two cause:
1. This usually results from trying to connect to a service that is inactive on the foreign host. 2. Sometimes a 10061 error is caused by either a firewall or anti-virus software presence on the local computer or network connection.

Either one may be blocking the ports needed to make a successful connection to the server. Either you went to the wrong host, or the server application you're trying to contact is not executing. Check the destination address you are using. Check, if you used a hostname, did it resolve to the correct address or not..

--Amit
 
Share this answer
 
According to me port is the problem,
So Please Check below method.

C#
var fromAddress = "Gmail@gmail.com";
  // any address where the email will be sending
  var toAddress = YourEmail.Text.ToString();
  //Password of your gmail address
  const string fromPassword = "Password";
   // Passing the values and make a email formate to display
  string subject = YourSubject.Text.ToString();
  string body = "From: " + YourName.Text + "\n";
  body += "Email: " + YourEmail.Text + "\n";
  body += "Subject: " + YourSubject.Text + "\n";
  body += "Question: \n" + Comments.Text + "\n";
  // smtp settings
  var smtp = new System.Net.Mail.SmtpClient();
  {
      smtp.Host = "smtp.gmail.com";
      smtp.Port = 587;
      smtp.EnableSsl = true;
      smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
      smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
      smtp.Timeout = 20000;
  }
  // Passing values to smtp object
  smtp.Send(fromAddress, toAddress, subject, body);
 
Share this answer
 
 
Share this answer
 
If your system is in proxy server then your mail will not send. Please check your server first.
 
Share this answer
 

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