Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MailMessage mm = new MailMessage();
     mm.To.Add(receiver);
     mm.Body = body;
     mm.From = new MailAddress("feedback@delwyntech.com");
     mm.Subject = sub;
     try
     {
         Ping ping = new Ping();
         PingReply pingreply = ping.Send("gmail.com");
         string x = pingreply.Status.ToString();
         if (x == "Success")
         {
             SmtpClient smtp = new SmtpClient();
             try
             {
                 smtp.Host = "smtpout.secureserver.net";
                 smtp.EnableSsl = true; //Depending on server SSL Settings true/false
                 System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                 NetworkCred.UserName = "feedback@gowyn.com";
                 NetworkCred.Password = "password";
                 smtp.Credentials = NetworkCred;
                 smtp.UseDefaultCredentials = true;
                 smtp.Port = 465;//Specify your port No;
                 smtp.Send(mm);



Exception Detail:

System.Net.Mail.SmtpException was caught
  Message=Failure sending mail.
  Source=System
  StackTrace:
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at db_fn.sendemail(String body, String sub, String sender, String receiver) in c:\Users\Administrator\Dropbox\crm\App_Code\db_fn.cs:line 225
  InnerException: System.IO.IOException
       Message=Unable to read data from the transport connection: net_io_connectionclosed.
       Source=System
       StackTrace:
            at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
            at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
            at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
            at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpClient.GetConnection()
            at System.Net.Mail.SmtpClient.Send(MailMessage message)
       InnerException: 



Plz help me out..!!!!!!
Posted
Updated 9-Mar-13 4:02am
v2
Comments
[no name] 9-Mar-13 9:57am    
Please post the real error message that you are getting, along with the stack trace and identify the line of code that is getting the error. Unless you are really getting an SQL error, then post that code instead.
Sanjeev236 9-Mar-13 10:02am    
thnaks.. question modified..!!

mike meinz is correct the UseDefaultCredentials should be false. Aside from that I would check the port as well the most commonly used ports are 10, 25, 110 465, and 587. I have personally had more luck with port 587.
 
Share this answer
 
Comments
Sanjeev236 10-Mar-13 0:07am    
changes defaultcredentials to false..but still problem persists.
tried other ports too... and for further info,same port 465 is working great in outlook.!!!!
Mike Meinz 10-Mar-13 10:14am    
Sorry. The only other thing I can think of is maybe the login id NetworkCred.UserName should just be the username part of the email address and not include the @domainname part.
charles henington 11-Mar-13 6:53am    
not sure but i know in most cases the @domainname part must be included.
also ive noticed that you call the smtp.UseDefaultCredentials = false; after you specify the NetworkCredentials try calling the UseDefaultCredentials = false before you change the Credentials when i sent a message with gmail it must be done in this manner or an error will be thrown
C#
private void button1_Click(object sender, EventArgs e)
        {
            string reciever = "recipent";
            string subject = "subject";
            string body = "body";
            try
            {
                using (MailMessage message = new MailMessage("feedback@delwyntech.com", reciever)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    using (SmtpClient client = new SmtpClient("smtpout.secureserver.net", 465)
                    {
                        EnableSsl = true,
                        UseDefaultCredentials = false,
                        Credentials = new NetworkCredential("feedback@gowyn.com", "password")
                    })
                    {
                        client.Send(message);
                    }
                }
            }
            catch (Exception mailException)
            {
                // if an exception is thrown display exception message for debug  purposes
                MessageBox.Show(mailException.Message);
            }
        }
 
Share this answer
 
Comments
Sanjeev236 12-Mar-13 5:16am    
System.Net.Mail.SmtpException was caught
Message=Failure sending mail.
Source=System
StackTrace:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Sent_mail.Button2_Click(Object sender, EventArgs e) in c:\Documents and Settings\admin\My Documents\Dropbox\crm\Sent_mail.aspx.cs:line 69
InnerException: System.IO.IOException
Message=Unable to read data from the transport connection: net_io_connectionclosed.
Source=System
StackTrace:
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
InnerException:


Sorry Charles No Luck... :( Still i appreciate your work heartly.
charles henington 12-Mar-13 13:26pm    
try it on port 80 and alternating EnableSsl i know that when using yahoo EnableSsl must be set to false perhaps thats the case here. also check out http://support.godaddy.com/groups/email/forum/topic/cant-send-email-using-smtpout-secureserver-net/.
theres an interesting fix with the server address perhaps that may be of assistance to you
I found these two documentation items. Maybe one or both of these will help you solve this problem.

The documentation for SmtpClient.EnableSsl Property[^] says:
If the EnableSsl property is set to true, and the SMTP mail server does not advertise STARTTLS in the response to the EHLO command, then a call to the Send or SendAsync methods will throw an SmtpException.

The documentation for SmtpClient.UseDefaultCredentials Property[^] says:
Set this property to true when this SmtpClient object should, if requested by the server, authenticate using the default credentials of the currently logged on user. For client applications, this is the desired behavior in most scenarios.
The tag for your question says ASP.NET so it is not a Client Application. Perhaps UseDefaultCredentials should be False since you are supplying the credentials.
 
Share this answer
 
Comments
Sanjeev236 10-Mar-13 0:06am    
changes defaultcredentials to false..but still problem persists.
SmtpClient ss = new SmtpClient();
               ss.Host = "relay-hosting.secureserver.net";
                ss.Port = 25;
                ss.Timeout = 10000;
                ss.DeliveryMethod = SmtpDeliveryMethod.Network;
                ss.UseDefaultCredentials = false;
                ss.Credentials = new NetworkCredential("your_full_emailAddress", "YourPassword", "your_Domain");
                ss.EnableSsl = false;
 
                MailMessage mailMsg = new MailMessage("your_full_emailAddress", "demo@gmail.com", "subject here", "my body");
                mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                ss.Send(mailMsg);
 
                Response.Write("Mail Sent");
 
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