什么是SMTP.MAIL的原因:操作超时? [英] what is the cause of SMTP.MAIL: the Operation has timed out?

查看:2833
本文介绍了什么是SMTP.MAIL的原因:操作超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个内联网的基于Web的应用程序,它会发送通知,具体取决于管理员的选择,它的用户。

I am creating an intranet web-based application that will send notifications to its users depending on the Admin's choice.

我正确地开发的邮件页面,它做工精细用15或20个用户。现在,我有超过200个用户,所以当我运行这个页面,我得到了下面的错误,我不知道为什么:

异常详细信息:System.Net.Mail.SmtpException:操作已
  超时。

Exception Details: System.Net.Mail.SmtpException: The operation has timed out.

我的code-背后(C#):

My Code-Behind (C#):

protected void Page_Load(object sender, EventArgs e)
    {
        SendEmailTOAllUser();
    }


    protected void SendEmail(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
    {
        SmtpClient sc = new SmtpClient("MAIL.companyDomainName.com");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("pssp@companyDomainName.com", "PMOD Safety Services Portal (PSSP)");

            // In case the mail system doesn't like no to recipients. This could be removed
            //msg.To.Add("pssp@companyDomainName.com");

            msg.Bcc.Add(toAddresses);
            msg.Subject = MailSubject;
            msg.Body = MessageBody;
            msg.IsBodyHtml = isBodyHtml;
            //Response.Write(msg);
            sc.Send(msg);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    protected void SendEmailTOAllUser()

    {
        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspEmail;Integrated Security=True";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            var sbEmailAddresses = new System.Text.StringBuilder(1000);
            string quizid = "";

            // Open DB connection.
            conn.Open();

            string cmdText = "SELECT MIN (QuizID) As mQuizID FROM dbo.QUIZ WHERE IsSent <> 1";
            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        // There is only 1 column, so just retrieve it using the ordinal position
                        quizid = reader["mQuizID"].ToString();

                    }
                }
                reader.Close();
            }

            string cmdText2 = "SELECT Username FROM dbo.employee";
            using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
            {
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var sName = reader.GetString(0);
                        if (!string.IsNullOrEmpty(sName))
                        {
                            if (sbEmailAddresses.Length != 0)
                            {
                                sbEmailAddresses.Append(",");
                            }
                            // Just use the ordinal position for the user name since there is only 1 column
                            sbEmailAddresses.Append(sName).Append("@companyDomainName.com");
                        }
                    }
                }
                reader.Close();
            }

            string cmdText3 = "UPDATE dbo.Quiz SET IsSent = 1 WHERE QuizId = @QuizID";
            using (SqlCommand cmd = new SqlCommand(cmdText3, conn))
            {
                // Add the parameter to the command
                var oParameter = cmd.Parameters.Add("@QuizID", SqlDbType.Int);
                // Get a local copy of the email addresses
                var sEMailAddresses = sbEmailAddresses.ToString();


                    string link = "<a href='http://pmv/pssp/StartQuiz.aspx?testid=" + quizid + "'> Click here to participate </a>";
                    string body = @"Good day, <br /><br />
                                <b> Please participate in the new short safety quiz </b>"
                                        + link +
                                        @"<br /><br />
                            Also, give yourself a chance to gain more safety culture by reading the PMOD Newsletter.
                            <br /> <br /><br /> <br />
                            This email was generated using the <a href='http://pmv/pssp/Default.aspx'>PMOD Safety Services Portal (PSSP) </a>. 
                            Please do not reply to this email.
                            ";

                    SendEmail(sEMailAddresses, "", "Notification of New Weekly Safety Quiz", body, true);

                    // Update the parameter for the current quiz
                    oParameter.Value = quizid;
                    // And execute the command
                    cmd.ExecuteNonQuery();
            }
            conn.Close();
        }
    }

任何帮助吗?

推荐答案

添加 sc.timeout = 600000(10分钟)
在发送电子邮件的方法。

add sc.timeout=600000(10min) in send email method.

如果邮件发送需要更多的时间来完成它可以让你

if email send requires more time to complete the it allows you

这篇关于什么是SMTP.MAIL的原因:操作超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆