简体   繁体   English

操作已超时。 使用C#ASP.net通过smtp发送电子邮件时

[英]The operation has timed out. while sending email through smtp using C# ASP.net

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. 我收到“操作超时”错误,当我通过我的smtp服务器发送电子邮件时,我陷入了异常。我将代码与gmail smtp一起使用,并且相同的代码也能正常工作。在smtp详细信息中,我正在使用网络凭据作为我在域,传出服务器和smtp端口上创建电子邮件帐户时获得的用户名和密码。 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;
        }  

    }

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? 答:我100%确定服务器连接字符串正确吗? Also port wise? 还是明智的?

B, Am I sure the ports are open for this communication to happen?(Check the firewalls are open) B,我确定端口已打开以进行此通信吗?(检查防火墙是否打开)

C, Am I that there isn't some sort of version or configuration that is different between the gmail smtp, and you local smtp? C,我在gmail smtp和您的本地smtp之间没有某种不同的版本或配置吗?

D, Check the SMTP server logs, if you are even receiving the request. D,如果您甚至收到请求,请检查SMTP服务器日志。

D1, if you are receiving, check which error is causing the timneout, this will likely be in the log. D1,如果您正在接收,请检查是哪个错误导致了音调异常,这很可能在日志中。

D2, Start from A, There is something wrong with your connection to the SMTP server. D2,从A开始,您与SMTP服务器的连接有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM