Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
pls what is d problem with d is code,its not sending my mail,any lead


XML
<%@ Import Namespace="System.Net.Mail" %>

<SCRIPT Runat="Server">

Sub Send_Email (Src As Object, Args As EventArgs)

   If MailFrom.Text <> "" _
      AND MailTo.Text <> "" _
      AND Subject.Text <> "" _
      AND Body.Text <> "" Then
         Try
            Dim MailClient = New SmtpClient("mail.eaglejobsng.com")
            MailClient.Send(MailFrom.Text,MailTo.Text,Subject.Text,Body.Text)
            MailMsg.Text = "Email sent"
         Catch
            MailMsg.Text = "Error in sending email!"
         End Try
   End If

End Sub

</SCRIPT>

<form Runat="Server">

<h3>Send Email</h3>

<table border="1" style="border-collapse:collapse">
<tr>
   <td style="font-weight:bold; background-color:#E0E0E0">To:</td>
   <td><asp:TextBox id="MailTo" Width="200" Runat="Server"/></td>
</tr>
<tr>
   <td style="font-weight:bold; background-color:#E0E0E0">From:</td>
   <td><asp:TextBox id="MailFrom" Width="200" Runat="Server"/></td>
</tr>
<tr>
   <td style="font-weight:bold; background-color:#E0E0E0">Subject:</td>
   <td><asp:TextBox id="Subject" Width="300" Runat="Server"/></td>
</tr>
<tr>
   <td style="font-weight:bold; background-color:#E0E0E0">Message:</td>
   <td><asp:TextBox id="Body" Runat="Server"
            TextMode="MultiLine" Rows="5" Width="300"
            Font-Name="Arial"/></td>
</tr>
</table>
<br/>
<asp:Button Text="Send Email" OnClick="Send_Email" Runat="Server"/>
<asp:Label id="MailMsg" ForeColor="#FF0000" Runat="Server"/>

</form>


Author's update:

the error message is always "Error in sending email"
Posted
Updated 26-Jan-11 15:31pm
v3

Your problems are many.

1 - you use txt speak, like a moron
2 - you don't tell us the error message

I'd say the odds are good that this is not a public server, and so the code you've given does not work because it can't connect to the server, but it's impossible to know ,based on this lack of information.
 
Share this answer
 
Comments
fjdiewornncalwe 26-Jan-11 20:42pm    
Wow. You read my mind, Christian
I am with Christian.

But the below post will help you,

A Simple But Effective Way to Send an Email using SmtpClient Class[^]
 
Share this answer
 
It can be because of various reasons. You need to look at them one by one.
Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>

If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]
 
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