Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why this code is not running
ASP.NET
<%@ Page Language="C#" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="True"%>

<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Net.Mail" %>

<script  runat="server">
 void send(Object sender, EventArgs e)
    {
   SmtpClient smtpClient = new SmtpClient();
   MailMessage message = new MailMessage(); 
   try       
   {        
    MailAddress fromAddress = new MailAddress(t1.Text, t2.Text);
    smtpClient.Host = "webmail.kamnatrust.com";     
    smtpClient.Port = 80; 
    message.From = fromAddress;
    message.To.Add("janardan.ind@gmail.com");
    message.Subject = "Feedback";
    message.IsBodyHtml = false;
    message.Body = t3.Text;
    smtpClient.Send(message);
    l1.Text = "Email successfully sent.";
    }
    catch (Exception ex)
    {
    l1.Text = "Send Email Failed.<br>" + ex.Message;
    }
    }
	}
</script>
<html>

<body>
<form  runat="server">
<table>
<tr><td>
 Enter Email<asp:TextBox ID="t1" runat="server"/><br>
 Name <asp:TextBox ID="t2" runat="server"/>
  <br>
  Subject<asp:TextBox ID="t3" runat="server"/>
  <br>
 Click to send <asp:Button ID="b1" Text="send" OnClick="send" runat="server"/>
 <br>
 <asp:Label ID="l1" runat="server"/>
</br></br></br></br></td></tr>
</table>
</form>
</body>
</html>
</br>
Posted
Updated 4-Nov-11 22:31pm
v2

The same reason that all your other versions are not working. You really need to spend some more time studying this class[^] and its associated objects. You then need to learn how to access the smtp port of your chosen host. If necessary look at the host system's help to find out the correct host name and port number to use. And finally, make sure you have chosen a host that actually provides an SMTP service.
 
Share this answer
 
v2
Comments
RaviRanjanKr 5-Nov-11 5:19am    
Nice suggestion Richard, My 5+
Richard MacCutchan 5-Nov-11 9:36am    
Thanks. I don't know if you've been following OP's questions on this subject but he clearly does not grasp what SMTP is about.
Your mail server's SMTP address is definitely not on port 80.

Contact you mail servers admin and ask for the SMTP port number (default is 25 but it could be something else).
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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