0

I am getting error "operation time out"and it throws me to the exception when i am sending email through my smtp server.I am using the code with gmail smtp and the same code works fine.In smtp details I am using network credential as my username and password i got when i created my email account on my domain and outgoing server and smtp port. following is my code..

protected void send_Click(object sender, EventArgs e)
        {
            string to = "xyz@gmail.com"; //To address    
            string from = "xyz@gmail.com"; //From address    
            MailMessage message = new MailMessage(from, to);
            string mailbody = "Welcome to gmail...";
            message.Subject = "Sending Email";
            message.Body = mailbody;
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("server host",port);     
            System.Net.NetworkCredential basicCredential1 = new
            System.Net.NetworkCredential("Username ","Password");
            client.EnableSsl = true;
            //client.Timeout = 10000;
            client.UseDefaultCredentials =false;
            client.Credentials = basicCredential1;
            try
            {
                client.Send(message);
            }

        catch (Exception ex)
        {
            throw ex;
        }  

    }

1 Answers1

0

Because you haven't posted any log data, what you have already tried, and what didn't work, and only giving us the timeout as an outcome, there are a lot of open ended questions to your question. So instead of a specific answer, all I can do is give you vague directions what you need to do, to resolve your issue.

There can be a lot of issues with this sort of thing. You write that this code performs correctly with another server, if I understand you correctly?

I would check:

A, Am I 100% sure my server connection string is correct? Also port wise?

B, Am I sure the ports are open for this communication to happen?(Check the firewalls are open)

C, Am I that there isn't some sort of version or configuration that is different between the gmail smtp, and you local smtp?

D, Check the SMTP server logs, if you are even receiving the request.

D1, if you are receiving, check which error is causing the timneout, this will likely be in the log.

D2, Start from A, There is something wrong with your connection to the SMTP server.

Morten Bork
  • 942
  • 8
  • 18