Click here to Skip to main content
12,956,410 members (77,025 online)
Rate this:
Please Sign up or sign in to vote.
my code : that is timeout or failure.
////my message setting 
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("");
            msg.Body = "body my mail";
            msg.Subject = "my mail subject";
            //msg.IsBodyHtml = true;
            //msg.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient();
            client.UseDefaultCredentials = false;
            client.Credentials=new NetworkCredential("", "PWD",";
            client.Host = "";
            client.Port = 465;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;

      <smtp from="" deliverymethod="Network">
        <network defaultcredentials="false" enablessl="true" host="" port="465" password="pwd" username="mygmail" />

Please help me.
Posted 8-Mar-12 10:04am
Updated 8-Mar-12 10:10am
mark merrens 8-Mar-12 16:08pm
Please format correctly. What is the exception you are getting? Note: if you copied and pasted the code above from your class there is a missing quote mark at: new NetworkCredential("", "PWD",";
Ed Nutting 8-Mar-12 16:12pm
I want a exact error code - to put it in your words. How can we help you if you don't give any details as to what the error actually is!? "Timeout or failure" covers just about every error possible!
sadegh_rusta 8-Mar-12 16:28pm
i do it.but not ok
sadegh_rusta 8-Mar-12 16:29pm
/???i dont know where is error in my code
Ed Nutting 8-Mar-12 16:32pm
apparently... look the code must be either throwing an exception - in which case you need to put a try/catch block round it and gives us the specific error message - or the web server is returning an error code/message so you need to tell use what that is.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Change your port number to 587 and try once.

Refer this code

public int SendUserMail(string fromad, string toad, string body, string header, string subjectcontent)
        int result = 0;
        MailMessage usermail = Mailbodplain(fromad, toad, body, header, subjectcontent);
        SmtpClient client = new SmtpClient();
        //Add the Creddentials- use your own email id and password
        client.Credentials = new System.Net.NetworkCredential("your user id ", "pwd"); ;
        client.Host = "";
        client.Port = 587;
        client.EnableSsl = true; 
            result = 1;
        catch (Exception ex)
            result = 0;
        } // end try 
        return result;
    public MailMessage Mailbodplain(string fromad, string toad, string body, string header, string subjectcontent)
        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            string from = fromad; 
            string to = toad; 
            mail.From = new MailAddress(from, header, System.Text.Encoding.UTF8);
            mail.Subject = subjectcontent;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = body;
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = true;
            mail.Priority = MailPriority.High;
        catch (Exception ex)
        return mail;
sadegh_rusta 9-Mar-12 15:18pm
ok thx
it is ok
sadegh_rusta 9-Mar-12 15:18pm
ok thx
it is ok
sadegh_rusta 10-Mar-12 16:14pm
but after run,i have this error :
smtpexeception was caught

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
please help me

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
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 9 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100