<% userPageRights="{mail}" %>
<!--#include file="check.asp"-->
<!--#include file="../Include/char.asp" -->
<!--#include file="../MailList/MailListConst.asp" -->
<!--#include file="../MailList/Email.asp" -->
<%
    'Const
    mSenderName = MailListInfo(0)
    mSenderEmail = MailListInfo(1)
	mAD = MailListInfo(3)
	mDefaultSubject = MailListInfo(2)

	mCharset = MailListInfo(8)
	mModule = MailListInfo(9)
	mSmtpAddress = MailListInfo(10)
	mSmtpUserName = MailListInfo(11)
	mSmtpPassowrd = MailListInfo(12)
  if Request.ServerVariables("REQUEST_METHOD")="POST" then
	'Request var
	m_ContentType = "text/html"
	m_Priority = Request.Form("radPriority")
    m_Email = checkStr(Trim(Request.Form("txtEmail")))
    m_Email2 = checkStr(Trim(Request.Form("txtEmail2")))
    m_Email3 = checkStr(Trim(Request.Form("txtEmail3")))
	m_Subject = checkStr(Trim(Request.Form("txtSubject")))
	m_Body = checkStr(rTrim(Request.Form("txtContent")))
	m_Sender = checkStr(rTrim(Request.Form("txtSenderEmail")))
	m_SenderName = checkStr(rTrim(Request.Form("txtSenderName")))
    mUserGroupID = Request.Form("selUserGroupID")
	if Request.Form("chkIsTake")="1" then mIsTake = 1 else mIsTake = 0
	if Request.Form("radFormat")="1" then SendContentType = "text/html" else SendContentType = "text/plain"

    If mUserGroupID="-1" then
	  Call OneSend()
	Else
	  Call GroupSend()
	End if 
  End if

  '单发一封邮件
  Sub OneSend()
    if instr(m_Email,"@")=0 then
      call MsgBox("对不起，您的邮件格式错误!",1)
    else
	  SendMail = UseJmail(m_Email,m_Subject,m_Body,m_Sender,m_SenderName)
	  if SendMail="OK" then
	    call MsgBox("祝贺您，邮件发送成功！",1)
	  Else
	    call MsgBox( "对不起，邮件发送失败，错误原因:<br>"&SendMail,1)
	  End if
	end if
  End Sub

  '群发邮件
  Sub GroupSend()
    mSql = "Select F_Email,F_UserName,F_TakeContent From MailList_User Where F_UserGroupID="&mUserGroupID& " and F_IsTake="&mIsTake
    Set rs = conn.Execute(mSql)
	if rs.Eof then 
	  call MsgBox("对不起，找不到要发送的列表！",1)
    else
	  ArrSendList = rs.GetRows()
      '发送成功Number,发送失败Number,格式错误Number,错误原因
	  dim mSendOKNumber,mSendErrNumber,mFormatErrNumber,mErrReason
	  mSendOKNumber = 0:mSendErrNumber = 0:mFormatErrNumber = 0:mErrReason = ""
      '格式错误的Email
	  dim mErrEmail
  	  mErrEmail = "" : 
      for i=0 to ubound(ArrSendList,2)
		if Instr(ArrSendList(0,i),"@")<>0 then
		   m_Email = ArrSendList(0,i)
	   	   SendMail = UseJmail(m_Email,m_Subject,m_Body,m_Sender,m_SenderName)
		   if SendMail="OK" then 
		     mSendOKNumber = mSendOKNumber+1 
		   else 
	   	      SendMail = UseJmail()
	          if SendMail="OK" then 
		        mSendOKNumber = mSendOKNumber+1 
			  else
		        mSendErrNumber = mSendErrNumber+1
			    mErrReason = mErrReason + SendMail&"<br>"
			  End if
		   end if
		Else
		   mErrEmail = mErrEmail+ArrSendList(0,i)+"<br>"
		   mFormatErrNumber = mFormatErrNumber+1
		End if
	  Next
	  ResultInfo = "<b>群发报告：</b><br>成功发送了["&mSendOKNumber&"]封邮件!<br>"
	  ResultInfo = ResultInfo + "由于不可知原因有["&mSendErrNumber&"]封邮件发送失败！<br>"
	  ResultInfo = ResultInfo + "发送失败的原因:<br>"&mErrReason
	  ResultInfo = ResultInfo + "对不起由于邮件格式错误,有["&mFormatErrNumber&"]封邮件无法发出!<br>"
	  ResultInfo = ResultInfo + "格式错误的邮件:<br>"&mErrEmail
	  Response.Write ResultInfo
	end if
  End Sub
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="Images/Style.css" rel="stylesheet" type="text/css">
</head>
<BODY bgcolor="D6DFF7" leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<TABLE width=100% height=96% border=0 align="center" cellPadding=0 
cellSpacing=0 >
  <TBODY>
    <TR> 
      <TD width="100%" valign="top" align="center">

<form name="form1" method="post" action="?">
          <br>
          <table class=tableBorder width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
        <tr> 
              <th height=22 colspan="7" align="center" sytle="line-height:150%">邮件发送/群发</th>
       </tr>
		    <tr> 
              <td class=forumRow width="14%" height="27" valign="bottom">收信人地址:</td>
              <td class=forumRowHighlight width="86%" height="27" colspan="5" valign="bottom"> <input name="txtEmail" type="text" class=INPUT value="<%=Request("Email")%>" size="35"> 
                <label for=HighLight >选群发可不填</label> </td>
            </tr>
            <tr> 
              <td class=forumRow height="20" width="14%"><font color="#999999">抄送地址:</font></td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"> <input type="text" name="txtEmail2" class=INPUT size="35"> 
              </td>
            </tr>
            <tr> 
              <td class=forumRow height="20" width="14%"><font color="#999999">暗送地址:</font></td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"> <input type="text" name="txtEmail3" size="35" class=INPUT> 
              </td>
            </tr>
            <tr> 
              <td class=forumRow width="14%" height="20">信件主题:</td>
              <td class=forumRowHighlight colspan="5" width="86%"> <input name="txtSubject" type="text" class="INPUT" size="66">
                ←<a href="javascript:" onClick="document.form1.txtSubject.value='<%=mDefaultSubject%>'">默认</a></td>
            </tr>
            <tr> 
              <td class=forumRow height="20" width="14%">信件格式:</td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"><input type="radio" name="radFormat" value="0" >
                文本邮件 
                <input name="radFormat" type="radio" value="1" checked >
                HTML邮件</td>
            </tr>
            <tr> 
              <td class=forumRow width="14%" height="20">信件内容:</td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"> <textarea name="txtContent" cols="66" class="INPUT" rows="14"></textarea>
              </td>
            </tr>
            <tr> 
              <td class=forumRow height="10" width="14%">发送对像:</td>
              <td class=forumRowHighlight width="86%" height="10" colspan="5">
			        <select name="selUserGroupID">
					
                          <%
                           response.write "<option value='-1'>====单独发送====</option>"
						   mSql = "Select F_ID,F_Value From MailList_UserGroup"
						   Set rst = conn.Execute(mSql)
						   Do While Not rst.Eof
                             response.write "<option value='" & rst("F_ID") &"'>群发To:"& rst("F_Value") &"</option>"
						     rst.MoveNext
						   Loop
						   rst.Close
						   %>
                     </select>
                <input type="checkbox" name="chkIsTake" value="1">
                已订阅</td>
            </tr>
            <tr> 
              <td class=forumRow height="10">邮件等级:</td>
              <td class=forumRowHighlight width="86%" height="10" colspan="5">
			    <input type="radio" name="radPriority" value="1" >
                加急 
                <input name="radPriority" type="radio" value="3" checked >
                普通 
                <input type="radio" name="radPriority" value="5" >
                低级</td>
            </tr>
            <tr> 
              <td class=forumRow height="20" width="14%">发信人名字:</td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"><input type="text" name="txtSenderName" class=INPUT value="黄冈信息港" size="35"></td>
            </tr>
            <tr> 
              <td class=forumRow height="20" width="14%">发信人地址:</td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"><input type="text" name="txtSenderEmail" class=INPUT value="029bxw@163.com" size="35"> 
              </td>
            </tr>
            <tr> 
              <td class=forumRow height="20" width="14%">&nbsp;</td>
              <td class=forumRowHighlight height="20" colspan="5" width="86%"> <input type="submit" name="Submit" value="提交" class=button> 
                <input type="reset" name="Submit2" value="重置" class=button> </td>
            </tr>
          </table>
		</form>
		</TD>
    </TR>
  </TBODY>
</TABLE>
</body>
</html>
<%call CloseDatabase()%>               