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

 <%
  
sendgo=Replace_Text(request.form("sendgo"))
if sendgo<>"" then 
  ' ============================================商机订阅自动发邮件===================================
	Set Rs=Server.CreateObject("Adodb.Recordset")
		Sql="select * from yixiang_emailorder"
		Rs.Open Sql,conn,1,3
		
	if not Rs.eof then 
 		do while not rs.eof 
			SendMail1=Rs("email")'接收人
			
				if Rs("orderflag")=1 then 
  				 Topc="您在"&webname&"订阅的商机信息"' 信件主题
				 Email_title="<table width='100%' cellpadding='0' cellspacing='0' style='font-size:14px; ' align='center' border=0>"
				 Email_title=Email_title&"<tr>"
				 Email_title=Email_title&"    <td ><span style='color:red'><strong>您在"&webname&"订阅的商机信息:</strong><br></span>"
				 Email_title=Email_title&"        <br>"
				 Email_title=Email_title&"      感谢您的支持，请点击以下链接，即可直接查看您订阅的求购信息(请登录后查看):<br>"
				 Email_title=Email_title&"      <br>"
				 Email_title=Email_title&"	  <ul style='line-height:24px;'>"

			'求购信息
				BuyKey=Rs("buyorder")
				BuyKey=Split(BuyKey,",")
				for i=0 to uBound(BuyKey)
					KeyWords=BuyKey(i)
					Call Email_key(KeyWords,"卖")
					
				next

				
				 Email_title=Email_title&"  </ul>"
				 Email_title=Email_title&"</td>"
				 Email_title=Email_title&"  </tr>"
				 Email_title=Email_title&"</table>"
				 Email_title=Email_title&"<table width='100%' cellpadding='0' cellspacing='0'  style='font-size:14px; '>"
				 Email_title=Email_title&"  <tr>"
				 Email_title=Email_title&"   <td colspan='2'>感谢您的支持，请点击以下链接，即可直接查看您订阅的供求信息(请登录后查看):<br>"
				 Email_title=Email_title&"      <br>"
				 Email_title=Email_title&"      <ul  style='line-height:24px;'>"
				
				
							'供应信息
							
								SellKey=Rs("saleorder")
								SellKey=Split(SellKey,",")
							for j=0 to uBound(SellKey)
									KeyWords=SellKey(j)
									Call Email_key(KeyWords,"买")		
							next
	
				 Email_title=Email_title&"    </ul>"
				 Email_title=Email_title&"</td>"
				 Email_title=Email_title&" </tr>"
				 Email_title=Email_title&"  <tr>"
				 Email_title=Email_title&"    <td width='61%' align='right'>"&webname&"管理员<br>"
				 Email_title=Email_title&date()&"</td>"
				 Email_title=Email_title&"    <td width='39%' align='right'><br></td>"
				 Email_title=Email_title&"  </tr>"
				 Email_title=Email_title&"  <tr align='center'>"
				 Email_title=Email_title&"    <td colspan='2'><br>"
				 Email_title=Email_title&"|-------------------------------------------------【<span style='color: #33FF66'>此信息谢绝回复</span>】----------------------------------------------|</td>"
				 Email_title=Email_title&" </tr>"
				 Email_title=Email_title&"</table>"
				 Email_title=Email_title&"<br><br><br>"
				 
 				SendTime=Rs("yx_Time")'上次发送时间
				
				if SendTime<>date() then 
					
					Rs("yx_Time")=date()
					Rs.update()
					if IsValidEmail(SendMail1)=true then   '发送邮件
						call SendMailto2(SMTPServer,SystemEmail,"admin",HOPE_MailUser,HOPE_MailPwd,"<"&SendMail1&">",SendMail1,Topc,Email_title)
					end if
				end if
	end if
 	 	Rs.MoveNext
	 if Rs.Eof then exit do 
		loop
	 end if
Rs.Close
Set Rs=nothing
response.Write("<script>alert('商机订阅自动匹配信息发送完毕！');location.href='Bs_Mail_Send.asp';</script>")
response.End()
end if
 

Sub  Email_key(keywords,TypeWho)
	
	WebUrlks=replace(replace(WebUrl,"/",""),"http:","http://")
 	if TypeWho="卖" then 
		LikePath="tradeinfo"
	else
		LikePath="seller"
	end if
	Set Rs_key=Server.CreateObject("Adodb.Recordset")
		Sql_key="Select * from yixiang_Info Where flag=1 and html_pass=1 and  type='"&TypeWho&"' and (showname like '%"&keywords&"%' or keywords like '%"&keywords&"%' or content  like '%"&keywords&"%')"
		Rs_key.Open Sql_key,conn,1,3
		if not  Rs_key.Eof then 
			
			Do While not Rs_key.Eof
				ttid=Rs_key("info_id")
				 sortid=Rs_key("sortid")
				 typeid=Rs_key("typeid")
				 typeid_2=Rs_key("typeid_2")
				 showname=Rs_key("showname")
				 dateandtime=Rs_key("dateandtime")
				 period=Rs_key("period")
				 showname=Rs_key("showname")
				Email_title=Email_title&"<li type='square'><a href='"&WebUrlks&HOPE_InstallDir&LikePath&"/offerdetail/"&sortid&"-"&typeid&"-"&typeid_2&"-"&ttid&".html' target='_blank'>"&WebUrlks&HOPE_InstallDir&LikePath&"/offerdetail/"&sortid&"-"&typeid&"-"&typeid_2&"-"&ttid&".html("&showname&")</a><br>"
	Rs_key.MoveNext
				IF Rs_key.Eof Then Exit do
			loop
		end if

		Rs_key.Close
		Set Rs_key=nothing
End Sub


Sub SendMailto2 (mailserver,frommail,frommailname,mailusername,mailuserpass,mailtoaddtitle,mailtoadd,mailtitle,mail_body)
	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  '屏蔽例外错误，返回FALSE跟TRUE两值 
	JMail.Charset = "gb2312"
	JMail.ContentType = "text/html"
	JMail.ISOEncodeHeaders = False
	JMail.MailServerUserName = mailusername    '发信人的邮件用户名
	JMail.MailServerPassword = mailuserpass    '发信人的邮件密码
	JMail.From = frommail                      '发件人的邮件地址
	JMail.FromName = frommailname              '发信人的名字
	JMail.Subject = mailtitle                  '邮件的标题
	JMail.Priority = 1
	JMail.AddHeader "Originating-IP",userip
	JMail.AddRecipient(mailtoadd)              '收件人地址
	JMail.Body = mail_body
	
	JMail.Send(mailserver)                     'SMTP地址         
	JMail.Close() 
	Set JMail = Nothing
 	
End Sub		
 %>
 
