Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET Javascript , +
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
Edited 8-Mar-12 10:10am
mark merrens at 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",";
sadegh_rusta at 8-Mar-12 16:28pm
i do it.but not ok
Ed Nutting at 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 at 8-Mar-12 16:29pm
/???i dont know where is error in my code
Ed Nutting at 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 at 9-Mar-12 15:18pm
ok thx
it is ok
sadegh_rusta at 9-Mar-12 15:18pm
ok thx
it is ok
sadegh_rusta at 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
0 Maciej Los 589
1 OriginalGriff 419
2 CPallini 205
3 RyanDev 175
4 Sergey Alexandrovich Kryukov 170
0 OriginalGriff 5,649
1 Sergey Alexandrovich Kryukov 4,783
2 Peter Leow 2,954
3 Maciej Los 2,689
4 DamithSL 2,465

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