Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I write a programe for sending mail, the code is bellow:-

C#
SqlCommand cmd2 = new SqlCommand("select name,femail from gr where inum='" + mylist[i].ToString() + "'", conn);
                         SqlDataReader rewder = cmd2.ExecuteReader();
                         while (rewder.Read())
                         {
                             MailAddress fromAddress = new MailAddress("yashpal@hry.nic.in", "Arun Trial for Email");

                             // You can specify the host name or ipaddress of your server
                             // Default in IIS will be lo
                             //smtpClient.Host = "localhost";
                             smtpClient.Host = "mail.nic.in";

                             //Default port will be 25
                             smtpClient.Port = 993;
                             smtpClient.EnableSsl = true;
                             //From address will be given as a MailAddress Object
                             message.From = fromAddress;
                             smtpClient.UseDefaultCredentials = true;
                            //  smtpClient.Credentials =  System.Net.NetworkCredential(userName, password);

                             // To address collection of MailAddress
                             message.To.Add(rewder[1].ToString());
                             message.Subject = "IAS's Transfer Orders";

                             // Send SMTP mail
                             
                             smtpClient.Send(message);




However, it throws an exception

"Operation timed out"
Posted
Updated 25-Nov-10 23:22pm
v2
Comments
Dalek Dave 26-Nov-10 5:22am    
Edited for Grammar and Code Block.

1 solution

Verify if your SmtpClient is correctly configurate, I have this error when the SmtpClient is incorrect.

Try with a other SmtpClient for confirm.

i.e.:
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.Credentials = new System.Net.NetworkCredential("EmailID", "Password");
 
Share this answer
 
v4

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