  <% 
	data_path="../../" 'ACC连接数据库路径，对SQL无效
	numid="19"
	dir="../err.asp" 
  %>
  <!--#include file="../../conn/conn.asp"-->
    <!--#include file="../rolecheck.asp"-->

<LINK href="../css/style.css" rel=stylesheet type=text/css>
<br /><br /><br />
<table cellpadding="2" cellspacing="1" border="0" width="560" align="center" class="a2">
	<tr>
		<td height="35" align="center" bgcolor="#CED8EC" ><strong>发 送 邮 件</strong></td>
	</tr>
	<tr class="a4">
		<td align="center" bgcolor="#DDE4F2">
      <br>
	       <br>
      <br>      
	  <% 
'发送
set rs=server.createobject("adodb.recordset") 
sql="select * from Websen_corporation "
rs.open sql,conn,1,3  

'设置发件人
fromname=request("frommail")
 
'设置发信人
	if request("frommail")<>"" then 
	strToemail=request("frommail")
	else
	strToemail = mail_username
	end if
	if instr(mailname,"@") then
		mailusername=left(mailname,instr(mailname,"@")-1)
	else
		mailusername = mailname
	end if
	if request("mail_pwd")<>"" then
		mailuserpass=request("mail_pwd")
	else
		mailuserpass=mail_pwd
	end if
if request("mail_smtp")<>"" then
mailaddress=request("mail_smtp")
else
mailaddress=mail_smtp
end if

'收信人


'设置邮件主题
strTitle=request("mailsubject")

'设置邮件内容
strContent=request("mailbody")

'判断对谁发信
tomail=request("tomail")
'写发信信息
 	if tomail<>"" then
		response.write "收信人地址："&tomail &"<br><br>"
	else
		response.write " 进行邮件群发！"&"<br><br>"
	end if


 response.write "发送主题：" & strTitle & "<br><br>"
 response.write "发送内容：" & strContent & "<br><br>"
 response.write "发送人：" & strToemail & "<br><br>"
 

Sub SendMail (mail_email,mail_subject,mail_body,mailusername,mailuserpass,mailaddress,fromname)
	On Error Resume Next
	Dim JMail
	userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")             
	If userip = "" Then userip = Request.ServerVariables("REMOTE_ADDR")    '获得真实IP这样的话在本地，在服务器测试都没有问题了
	
	Set JMail = Server.CreateObject("JMail.Message")
	JMail.silent = true
	JMail.Charset = "gb2312"
	JMail.ISOEncodeHeaders = False
	JMail.MailServerUserName = fromname '发信人的电子邮件地址
	JMail.MailServerPassword = mailuserpass              '发信人的电子邮件密码
	JMail.From = fromname 
	JMail.FromName = fromname                            '发信人的名字
	JMail.Subject = mail_subject
	JMail.Priority = 1
	JMail.AddHeader "Originating-IP",userip
	JMail.AddRecipient(mail_email)
	JMail.Body = mail_body
	JMail.Send(mailaddress)                        'SMTP地址         
	JMail.Close() 
	Set JMail = Nothing
 	
End Sub
 
if tomail<>"" then 
strToemailArray=split(tomail,",") 
for i=0 to UBound(strToemailArray)
	strToemailAddress=strToemailArray(i)
 	Call SendMail (strToemailAddress,strTitle,strContent,mailusername,mailuserpass,mailaddress,fromname)
Next	
else
do while not rs.eof 
 strToemailAddress=rs("email")
  	Call SendMail (strToemailAddress,strTitle,strContent,mailusername,mailuserpass,mailaddress,fromname)
  rs.movenext
loop

end if
	if err.Number<>0 then
         err.clear
         response.write " 发送失败!" & "&nbsp;&nbsp;&nbsp;"
		 response.write err.message
	  else
		  response.write " 发送完毕 !"& "&nbsp;&nbsp;&nbsp; "		  
	  end if
	  response.write "<a href=Bs_Mail_Send.asp>返回</a>"


%>  
			 <br>
      <br><BR><BR>
	  </td>
	</tr>
</table>
<BR>
 