如何向大量快速asp.net发送邮件 [英] How to send mail to large number fast asp.net

查看:77
本文介绍了如何向大量快速asp.net发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送邮件给大量快速的asp.net ....我需要一些时间...我的代码如下:

I want to send mail to large number fast asp.net....It takes some time for me...My code as follows:

string s14 = "select  email from  CandidateReg1";
         // string s14 = "select top 2 email from  CandidateReg1";
           DataTable d7 = cn.viewdatatable(s14);

           for (int m = 0; m < d7.Rows.Count; m++)
           {
               email = d7.Rows[m]["email"].ToString();
               sendmail();

           }




private void sendmail()
    {
        string s43 = "select top 1 mailid,password from EmailTable order by id desc";
        DataTable d47 = cn.viewdatatable(s43);
        for (int k = 0; k < d47.Rows.Count; k++)

        {



            companymailid = d47.Rows[k]["mailid"].ToString();

            password = d47.Rows[k]["password"].ToString();



        }

        SmtpClient smtp = new SmtpClient();

        smtp.Host = ConfigurationManager.AppSettings["SMTPServer"];

        //smtp.Port = 587;

        //smtp.EnableSsl = true;

        //smtp.UseDefaultCredentials = true;

        //if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["SMTPCredentialUser"]) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["SMTPCredentialPass"]))

        //{

        //    smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPCredentialUser"], ConfigurationManager.AppSettings["SMTPCredentialPass"]);

        //}

        smtp.Credentials = new System.Net.NetworkCredential(companymailid, password);



        MailMessage message = new MailMessage();

        // message.From = new MailAddress(companymailid);

        message.From = new MailAddress(companymailid);

        message.Subject = "Job Published";

        message.IsBodyHtml = true;

        StringBuilder body = new StringBuilder();

        body.Append("<table>");

        //body.Append("<tr><td>" + pass + "</td></tr>");

        body.Append("<tr><td>Published Job " + Session["jobtitle"].ToString() + ' ' + "with JobRefId (" + ' ' + Session["jobrefid"].ToString() + ')' + "</td></tr>");

        body.Append("</table>");
        body.Append("<br />");
        body.Append("<br />");
        body.Append("Sincerely,<br />");
        body.Append("<span style=\"font-weight: bold; color: #000099;\">Team - ResumeManager</span>");
        body.Append("<br />");
        body.Append("<br />");

        message.Body = body.ToString();
        message.To.Add(email);

        //message.To.Add("korathualex@gmail.com");
        try
        {
            smtp.Send(message);
            popupConfirm.ShowOnPageLoad = false;
            PopUpSendMailMsg.ShowOnPageLoad = true;
            lblmsg.Visible = false;
            lblmsgsendmail.Visible = true;
            lblmsgsendmail.Text = "Mail Send Successfully";

        }
        catch (Exception ex)
        {
            cn.WriteError(ex.Message);
        }
    }

推荐答案

重写sendmail函数中添加的代码以获取凭证,这样可以节省时间每次都从数据库获取电子邮件凭证。



Rewrite the code added in sendmail function to get the credential, It will save time to get email credential from database everytime.

string s43 = "select top 1 mailid,password from EmailTable order by id desc";
DataTable d47 = cn.viewdatatable(s43);
companymailid = d47.Rows[0]["mailid"].ToString();
password = d47.Rows[0]["password"].ToString();

 for (int m = 0; m < d7.Rows.Count; m++)
           {
               email = d7.Rows[m]["email"].ToString();
               sendmail(companymailid,password,email );

           }


只需删除
string s43 = "select top 1 mailid,password from EmailTable order by id desc";
       DataTable d47 = cn.viewdatatable(s43);
       for (int k = 0; k < d47.Rows.Count; k++)
       {

           companymailid = d47.Rows[k]["mailid"].ToString();
           password = d47.Rows[k]["password"].ToString();

       }





并在调用sendmail函数之前添加它。



from sendmail and add it before calling sendmail function.


快速完成大量任务的一种方法是通过线程化。

但你必须非常小心这种技术。



Microsoft已提供其Thread Pool Manager类以简化操作。



http://msdn.microsoft.com/en-us/library/0ka9477y.aspx [ ^ ]
One way to do large number of tasks quickly is by threading.
But you have to be very careful with this technique.

Microsoft has provided its Thread Pool Manager class to ease the things out.

http://msdn.microsoft.com/en-us/library/0ka9477y.aspx[^]


这篇关于如何向大量快速asp.net发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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