Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello...
I am a new member ...
I got a problem when i want to send email from my application, this is the error that I can:

System.Net.Mail.SmtpException was unhandled by user code
  Message=Failure sending mail.
  Source=System
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at _Default.SendEmail_Click(Object sender, EventArgs e) in C:\Users\Lenovo\Videos\EmailDemos\Default.aspx.vb:line 23
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.
RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.Net.WebException
       Message=Unable to connect to the remote server
       Source=System
       StackTrace:
            at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
            at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
            at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
            at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
            at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
            at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
            at System.Net.Mail.SmtpClient.GetConnection()
            at System.Net.Mail.SmtpClient.Send(MailMessage message)
       InnerException: System.Net.Sockets.SocketException
            ErrorCode=10060
            Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 98.129.184.2:25
            NativeErrorCode=10060
            Source=System
            StackTrace:
                 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
                 at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
                 at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
            InnerException: 


I use this code:

VB
Protected Sub SendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendEmail.Click
       '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
       Const ToAddress As String = "yeni@kahar.co.id"

       '(1) Create the MailMessage instance
       Dim mm As New MailMessage(UsersEmail.Text, ToAddress)

       '(2) Assign the MailMessage's properties
       mm.Subject = Subject.Text
       mm.Body = Body.Text
       mm.IsBodyHtml = False

       '(3) Create the SmtpClient object
       Dim smtp As New SmtpClient

       '(4) Send the MailMessage (will use the Web.config settings)
       smtp.Send(mm)


       'Show the EmailSentForm Panel and hide the EmailForm Panel
       EmailSentForm.Visible = True
       EmailForm.Visible = False
   End Sub


Anyone.....
Please help me.....
Posted
Updated 23-Oct-12 0:18am
v2
Comments
BalaMahesh 23-Oct-12 7:14am    
Please try the below link
http://www.aspdotnet-suresh.com/2010/11/introduction-this-article-i-will.html

Put try catch blocks the you will know when is crashing .
please check the link

You missed the major thing in your code . where did you mentioned the SMTP server ?

refer the code below and refactor your code accordingly. (i am not so good in vb syntax so, providing a c# code)

C#
protected void SendMail()
{
    // Gmail Address from where you send the mail
    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"; // provide your smtpserver
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
// provide your stmp server credentials
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
}
 
Share this answer
 
use this link to solve problem

how to solve the error in email sending[^]
 
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