大量發送Mail的作法

摘要:大量發送Mail的作法

<%@ Page Language="C#" %>

<script runat="server">
    protected string send_in_processed = "";
    protected string status = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        send_in_processed = "開始發送";
        if (Request.QueryString["act"] != null && Request.QueryString["act"] != "")
        {
            if (Request.QueryString["act"] == "start")
            {
                status = "disabled";
                send_in_processed = "發送中";
            }
        }
    }
    protected void ShowJs(string msg)
    {
        Response.Write("<script language=javascript>");
        Response.Write("reportAction('" + msg + "');");
        Response.Write("</" + "script>\r\n");
        Response.Flush();
    }
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>mail發送</title>
    <link rel="stylesheet" href='../../ASPNETPortal.css' type="text/css">
</head>
<body>
    
    <form id="form1" runat="server">
        
    <script language="javascript" type="text/javascript">
    function reportAction(s)
    {
        document.getElementById("txtFeedback").value += s + "\r\n";
        var d = document.getElementById("txtFeedback").scrollHeight;
        document.getElementById("txtFeedback").scrollTop = d;
    }
    </script>
    <textarea name="txtFeedback" style="width: 80%; height: 200px" readonly id="txtFeedback"></textarea><br />
    <input type="button" name="submit" value=" <%=send_in_processed %>"  <%=status %> style="height: 25" onClick="window.location='?act=start'" id="btn">
    <input type="button" name="break" value="中斷" onclick="window.location='?act=break'" />
    
    </form>
</body>
</html>
<%
Response.Flush();
if (Request.QueryString["act"] != null && Request.QueryString["act"] != "")
{
    if (Request.QueryString["act"] == "start")
    {
        int sum = 0;        
        try
        {
            //這裡改為要發送的mail array
            for (int i = 0; i < 1000000; i++)
            {
                //send mail
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add(new System.Net.Mail.MailAddress("test@test.com"));
                msg.From = new MailAddress("test@test.com", "test@test.com", Encoding.Default);
                msg.Subject = "subject";
                msg.Body = "This is test mail";
                smtp.Send(msg);
                ShowJs(i.ToString() + "==>發送成功");
                sum++;
                if ((sum % 10) == 0)
                {
                    ShowJs("==========暫停 5 秒==========");
                    System.Threading.Thread.Sleep(5000);
                }
                System.Threading.Thread.Sleep(1000);
            }
            ShowJs("發送結束, 共寄送 " + sum.ToString() + " 筆。");
 
        }
        catch
        {
 
        }
    }
}
 
%>

 

網頁設計 -->找網站銀行

好站推薦:網頁設計除臭襪