DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1title>
<script language="C#" runat="server">... void Page_Load(Object sender, EventArgs e) ...{
this.ddlMailFormat.Items.Add( new ListItem( System.Enum.GetName(typeof(System.Web.Mail.MailFormat), MailFormat.Text), MailFormat.Text.ToString()));
this.ddlMailFormat.Items.Add( new ListItem( System.Enum.GetName(typeof(System.Web.Mail.MailFormat), MailFormat.Html), MailFormat.Html.ToString()));
}
void btnSend_Click(object sender, System.EventArgs e) ...{
try ...{
MailMessage Message = new MailMessage(); if( this.chkRequireLogin.Checked ) ...{
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" ); //basic authentication
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", txtUserName.Text ); //set your username here
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtPassword.Text ); //set your password here
}
Message.To = txtTo.Text;
Message.Cc = txtCC.Text;
Message.Bcc = txtBCC.Text;
Message.From = txtFrom.Text;
Message.Subject = txtSubject.Text;
Message.BodyFormat = (MailFormat)System.Enum.Parse(typeof(MailFormat), ddlMailFormat.SelectedValue );
Message.Body = txtMessage.Text; SmtpMail.SmtpServer = txtServer.Text;
SmtpMail.Send(Message); lblResult.Text = "Mail Sent";
}
catch( Exception ex ) ...{
lblResult.Text = ex.ToString();
}
} script>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblServer" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server"
Width="104px">Server:asp:Label>
<asp:Label id="lblMessage" style="Z-INDEX: 121; LEFT: 16px; POSITION: absolute; TOP: 280px"
runat="server" Width="104px">Message:asp:Label>
<asp:Label id="lblMailFormat" style="Z-INDEX: 120; LEFT: 16px; POSITION: absolute; TOP: 248px"
runat="server" Width="104px">Mail Format:asp:Label>
<asp:Label id="lblSubject" style="Z-INDEX: 119; LEFT: 16px; POSITION: absolute; TOP: 224px"
runat="server" Width="104px">Subject:asp:Label>
<asp:Label id="lblBCC" style="Z-INDEX: 118; LEFT: 16px; POSITION: absolute; TOP: 200px" runat="server"
Width="104px">BCC:asp:Label>
<asp:Label id="lblCC" style="Z-INDEX: 117; LEFT: 16px; POSITION: absolute; TOP: 176px" runat="server"
Width="104px">CC:asp:Label>
<asp:TextBox id="txtSubject" style="Z-INDEX: 114; LEFT: 128px; POSITION: absolute; TOP: 224px"
tabIndex="9" runat="server">Test of CDONTasp:TextBox>
<asp:TextBox id="txtBCC" style="Z-INDEX: 113; LEFT: 128px; POSITION: absolute; TOP: 200px" tabIndex="8"
runat="server">asp:TextBox>
<asp:TextBox id="txtCC" style="Z-INDEX: 112; LEFT: 128px; POSITION: absolute; TOP: 176px" tabIndex="7"
runat="server">asp:TextBox>
<asp:TextBox id="txtTo" style="Z-INDEX: 111; LEFT: 128px; POSITION: absolute; TOP: 152px" tabIndex="6"
runat="server">asp:TextBox>
<asp:TextBox id="txtFrom" style="Z-INDEX: 110; LEFT: 128px; POSITION: absolute; TOP: 128px" tabIndex="5"
runat="server">asp:TextBox>
<asp:TextBox id="txtPassword" style="Z-INDEX: 109; LEFT: 152px; POSITION: absolute; TOP: 88px"
tabIndex="4" runat="server" Width="128px" TextMode="Password">asp:TextBox>
<asp:TextBox id="txtUserName" style="Z-INDEX: 108; LEFT: 152px; POSITION: absolute; TOP: 64px"
tabIndex="3" runat="server" Width="128px">asp:TextBox>
<asp:Label id="lblTo" style="Z-INDEX: 106; LEFT: 16px; POSITION: absolute; TOP: 152px" runat="server"
Width="104px">To:asp:Label>
<asp:Label id="lblFrom" style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; TOP: 128px" runat="server"
Width="104px">From:asp:Label>
<asp:Label id="lblPassword" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 88px"
runat="server" Width="104px">Password:asp:Label>
<asp:Label id="lblUserName" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 64px"
runat="server" Width="104px">User Name:asp:Label>
<asp:CheckBox id="chkRequireLogin" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 40px"
runat="server" Width="232px" Text="Server Requires Login" tabIndex="2">asp:CheckBox>
<asp:TextBox id="txtServer" style="Z-INDEX: 107; LEFT: 128px; POSITION: absolute; TOP: 16px"
runat="server" tabIndex="1">asp:TextBox>
<asp:DropDownList id="ddlMailFormat" style="Z-INDEX: 115; LEFT: 128px; POSITION: absolute; TOP: 248px"
tabIndex="10" runat="server" Width="152px">asp:DropDownList>
<asp:TextBox id="txtMessage" style="Z-INDEX: 116; LEFT: 16px; POSITION: absolute; TOP: 304px"
tabIndex="11" runat="server" Width="280px" Height="136px" Rows="20" MaxLength="255">This is a test of CDONT Functionality.asp:TextBox>
<asp:Button id="btnSend" style="Z-INDEX: 122; LEFT: 240px; POSITION: absolute; TOP: 456px" tabIndex="12"
runat="server" Text="Send">asp:Button>
<asp:Label id="lblResult" style="Z-INDEX: 123; LEFT: 24px; POSITION: absolute; TOP: 496px"
runat="server" Width="100%" Height="200px">asp:Label>
form>
body>
HTML>
<HTML>
<HEAD>
<title>WebForm1title>
<script language="C#" runat="server">... void Page_Load(Object sender, EventArgs e) ...{
this.ddlMailFormat.Items.Add( new ListItem( System.Enum.GetName(typeof(System.Web.Mail.MailFormat), MailFormat.Text), MailFormat.Text.ToString()));
this.ddlMailFormat.Items.Add( new ListItem( System.Enum.GetName(typeof(System.Web.Mail.MailFormat), MailFormat.Html), MailFormat.Html.ToString()));
}
void btnSend_Click(object sender, System.EventArgs e) ...{
try ...{
MailMessage Message = new MailMessage(); if( this.chkRequireLogin.Checked ) ...{
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1" ); //basic authentication
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", txtUserName.Text ); //set your username here
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", txtPassword.Text ); //set your password here
}
Message.To = txtTo.Text;
Message.Cc = txtCC.Text;
Message.Bcc = txtBCC.Text;
Message.From = txtFrom.Text;
Message.Subject = txtSubject.Text;
Message.BodyFormat = (MailFormat)System.Enum.Parse(typeof(MailFormat), ddlMailFormat.SelectedValue );
Message.Body = txtMessage.Text; SmtpMail.SmtpServer = txtServer.Text;
SmtpMail.Send(Message); lblResult.Text = "Mail Sent";
}
catch( Exception ex ) ...{
lblResult.Text = ex.ToString();
}
} script>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblServer" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server"
Width="104px">Server:asp:Label>
<asp:Label id="lblMessage" style="Z-INDEX: 121; LEFT: 16px; POSITION: absolute; TOP: 280px"
runat="server" Width="104px">Message:asp:Label>
<asp:Label id="lblMailFormat" style="Z-INDEX: 120; LEFT: 16px; POSITION: absolute; TOP: 248px"
runat="server" Width="104px">Mail Format:asp:Label>
<asp:Label id="lblSubject" style="Z-INDEX: 119; LEFT: 16px; POSITION: absolute; TOP: 224px"
runat="server" Width="104px">Subject:asp:Label>
<asp:Label id="lblBCC" style="Z-INDEX: 118; LEFT: 16px; POSITION: absolute; TOP: 200px" runat="server"
Width="104px">BCC:asp:Label>
<asp:Label id="lblCC" style="Z-INDEX: 117; LEFT: 16px; POSITION: absolute; TOP: 176px" runat="server"
Width="104px">CC:asp:Label>
<asp:TextBox id="txtSubject" style="Z-INDEX: 114; LEFT: 128px; POSITION: absolute; TOP: 224px"
tabIndex="9" runat="server">Test of CDONTasp:TextBox>
<asp:TextBox id="txtBCC" style="Z-INDEX: 113; LEFT: 128px; POSITION: absolute; TOP: 200px" tabIndex="8"
runat="server">asp:TextBox>
<asp:TextBox id="txtCC" style="Z-INDEX: 112; LEFT: 128px; POSITION: absolute; TOP: 176px" tabIndex="7"
runat="server">asp:TextBox>
<asp:TextBox id="txtTo" style="Z-INDEX: 111; LEFT: 128px; POSITION: absolute; TOP: 152px" tabIndex="6"
runat="server">asp:TextBox>
<asp:TextBox id="txtFrom" style="Z-INDEX: 110; LEFT: 128px; POSITION: absolute; TOP: 128px" tabIndex="5"
runat="server">asp:TextBox>
<asp:TextBox id="txtPassword" style="Z-INDEX: 109; LEFT: 152px; POSITION: absolute; TOP: 88px"
tabIndex="4" runat="server" Width="128px" TextMode="Password">asp:TextBox>
<asp:TextBox id="txtUserName" style="Z-INDEX: 108; LEFT: 152px; POSITION: absolute; TOP: 64px"
tabIndex="3" runat="server" Width="128px">asp:TextBox>
<asp:Label id="lblTo" style="Z-INDEX: 106; LEFT: 16px; POSITION: absolute; TOP: 152px" runat="server"
Width="104px">To:asp:Label>
<asp:Label id="lblFrom" style="Z-INDEX: 105; LEFT: 16px; POSITION: absolute; TOP: 128px" runat="server"
Width="104px">From:asp:Label>
<asp:Label id="lblPassword" style="Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 88px"
runat="server" Width="104px">Password:asp:Label>
<asp:Label id="lblUserName" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 64px"
runat="server" Width="104px">User Name:asp:Label>
<asp:CheckBox id="chkRequireLogin" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 40px"
runat="server" Width="232px" Text="Server Requires Login" tabIndex="2">asp:CheckBox>
<asp:TextBox id="txtServer" style="Z-INDEX: 107; LEFT: 128px; POSITION: absolute; TOP: 16px"
runat="server" tabIndex="1">asp:TextBox>
<asp:DropDownList id="ddlMailFormat" style="Z-INDEX: 115; LEFT: 128px; POSITION: absolute; TOP: 248px"
tabIndex="10" runat="server" Width="152px">asp:DropDownList>
<asp:TextBox id="txtMessage" style="Z-INDEX: 116; LEFT: 16px; POSITION: absolute; TOP: 304px"
tabIndex="11" runat="server" Width="280px" Height="136px" Rows="20" MaxLength="255">This is a test of CDONT Functionality.asp:TextBox>
<asp:Button id="btnSend" style="Z-INDEX: 122; LEFT: 240px; POSITION: absolute; TOP: 456px" tabIndex="12"
runat="server" Text="Send">asp:Button>
<asp:Label id="lblResult" style="Z-INDEX: 123; LEFT: 24px; POSITION: absolute; TOP: 496px"
runat="server" Width="100%" Height="200px">asp:Label>
form>
body>
HTML>
send/attach user letter [file1 file2 ...]
send/attach user letter [[%filename data] ...]
Email地址存于MSSql一用户信息表中,数量上万。
公司自有服务器,集SMTP,POP3,WWW,FTP,MSSql,DNS等多种服务于一身。
JMAIL 有MailMerge对象,但是免费版不能用 要求:
用ASP+JMAIL,利用公司SMTP向所有用户发送EMAIL 思路:
直接读取数据库,多次循环发送,会对本来配置不高的服务器造成很大压力。
最好能对EMAIL分批发送,每批发送间隔一段时间,以此来缓解对服务器造成的压力。 实现:
对EMAIL分批
读出记录到recordset,利用常见的分页程序,将所有记录分页,每页作为一批,有多少页就分多少批
间隔延迟
在每页执行完毕后用<meta http-equiv="refresh" content="60;URL=SendMail.asp?page="&page>来延迟跳转
减少执行时间:
在循环的过程中,循环添加收件人,而不要循环发送,即
for i=1 to rs.pagesize
msg.AddRecipient rs("Email")
rs.movenext
next
msg.Send ("smtp.abc.com")
减小邮件大小
循环添加收件人,会造成一封Email的收件人很多,这样一封Email的就会很大。
所以,在以上代码的基础上改进一下,在循环内做个判断,当收件人Email数量到达
20的时候就发送一次。即:
for i=1 to rs.pagesize
msg.AddRecipient rs("Email")
if i mod 20 = 0 then '每 20 个收信人作为一封Email发送一次
msg.Send ("smtp.abc.com")
msg.ClearRecipients '清除已发送的收信人
end if
rs.movenext
next
msg.Send ("smtp.abc.com") '发送余下的
页面
Mail.asp 包含邮件主题、正文的表单,<form action="SendMail.asp" target="Send">;一个iframe页面,<iframe name="Send" src="SendMail.asp">
SendMail.asp 包含后台发送程序,循环,延迟跳转等。 缺点:
发送过程中不能离开该页面
发送的时间较长,与设置的每批发送数量、网络带宽、SMTP服务器性能有关 改进:
可以在Mail.asp中包含多个iframe页面,每个页面从不同的page开始发,相当于多线程发送,
对smtp服务器压力会增大,但能缩短发送时间。
可考虑在不同的page中采用不同的smtp服务器,例如包含多个iframe页面,在偶数页用
smtp.abc.com,在奇数页用smtp.123.com。这样既减轻服务器压力,也达到多线程发送
缩短发送时间的目的。
http://down.dvbbs.net/infoview/Article_2837.html
SqlConnection MyConn=new SqlConnection(MyConnectionString);
SqlDataAdapter MyDataAdapter=new SqlDataAdapter("select Email from T_User",MyConn);
DataSet MyDataSet=new DataSet();
MyDataAdapter.Fill(MyDataSet,"Email");
int EmailCount=MyDataSet.Tables["Email"].Rows.Count;
MailMessage email=new MailMessage();
// try
// {
for(int i=0;i<EmailCount;i++)
{
string context=Check(FreeTextBox1.Text.Trim());
SmtpMail.SmtpServer="127.0.0.1";
email.To=MyDataSet.Tables["Email"].Rows[i][0].ToString();
email.From="[email protected]";
email.Subject="注册信息";
email.Body=context;
email.BodyFormat=MailFormat.Html;
email.Priority=MailPriority.High;
SmtpMail.Send(email);
}
// }
//// catch
// {
// Response.Write("<script>alert('Send unSuccessful');</script>");
// }
用;分隔就可以了