Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why these error is giving Send Email Failed.Failure sending mail. in the below code?

HTML
<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>

C#
<%@ 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)
    {
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
 // System.Net.Mail.SmtpClient is the alternate class for this in 2.0 
  SmtpClient smtpClient = new SmtpClient();
   MailMessage message = new MailMessage(); 
   try       
{        
    MailAddress fromAddress = new MailAddress(t1.Text, t2.Text);
     
    smtpClient.Host = "localhost";     
   
    smtpClient.Port = 25; 
 
    message.From = fromAddress;

    message.To.Add("john_begginer@yahoo.co.in");
    message.Subject = "Feedback";
  
    message.IsBodyHtml = false;

    message.Body = t3.Text;
    // Send SMTP mail
    smtpClient.Send(message);
    l1.Text = "Email successfully sent.";
    }
    catch (Exception ex)
    {
    l1.Text = "Send Email Failed.<br>" + ex.Message;
    }
    }
</script>
</br>

Errors are giving - Error Send Email Failed.Failure sending mail.
Posted
Updated 4-Nov-11 0:24am
v2
Comments
Richard MacCutchan 4-Nov-11 6:27am    
Why are you sending to "localhost" rather than to the destination SMTP server?

Once check your server details correct or not
if correct then

Check This link

How to send email through asp.net[^]
 
Share this answer
 
v2
 
Share this answer
 
Refer this link:

Problem in Mail Sending[^]
 
Share this answer
 
You must send your email via a valid mail server address (you are using localhost).

You must also be authenticated on the email server to send otherwise you will be classified as spam and your IP address black listed.
 
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