<html xmlns="http://www.w3.org/1999/xhtml">
<!--#include file="../Inc/Conn.asp" -->
<!--#include file="../Inc/SK.Session.asp" -->
<!--#include file="../Inc/SK.Funtion.asp" -->
<!--#include file="../Inc/SK.PageClass.asp" -->
<%if Not (getconfig("SK_Office")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK100000000") AND JudgePopedomTF(Session("UserName"),"SK100000703")))) then Call ReturnError()%>
<%
'On Error Resume Next
Server.ScriptTimeout=10000000
set rspop3=server.CreateObject("adodb.recordset")
sqlpop3="select * from SK_SystemUsers where UsersID ="&Session("UID")&""
rspop3.open sqlpop3,conn,1,1

pop3Server=rspop3("SK_Pop3")
pop3user =rspop3("SK_Mailname")
pop3pwd =rspop3("SK_Mailpass")
pop3Email=rspop3("SK_Mailname")
myEmail=rspop3("SK_Email")

if pop3Server="" or pop3User="" or pop3Pwd="" then
Response.Write"<script>alert('对不起,邮箱配置有误');this.location.href='../Login/MyInfo.asp';</SCRIPT>"
response.End
end if
rspop3.close

Set pop3 = Server.CreateObject("JMail.POP3")
pop3.Connect ""&pop3user&"",""&pop3pwd&"",""&pop3Server&""
if pop3.count > 0 then
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>接收邮件</title>
<META http-equiv=Page-Enter content=SKCRM>
<META http-equiv=Page-Exit content=SKCRM>
<META content="MSHTML 6.00.3790.2858" name=GENERATOR>
<LINK href="../images/style.css" type=text/css rel=stylesheet>
<script type="text/javascript" src="../Inc/Check.js"></script>
<script language="javascript">
setTimeout("location.href='SK_MailReceive.asp'",20000);
</script>
<style type="text/css">
<!--
body {
margin: 5px 0px 5px 0px;
overflow-x:hidden;
overflow-y:auto;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<TBODY>
  <tr>
    <td class="SK_Td_Top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" height="25"><img src="../images/tab_03.gif" width="12" height="25" /></td>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="46%" valign="middle">邮件接收</td>
<td width="54%"></td>
</tr>
</table></td>
        <td width="16"><img src="../images/tab_07.gif" width="16" height="25" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="../images/tab_12.gif"></td>
<td>
</td>
<td background="../images/tab_15.gif"></td>
</tr>

<tr>
<td width="8" background="../images/tab_12.gif"></td>
<td>

<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">
<tr><td class="SK_Title1">接收邮件</td>
</tr>

<tr>
<td class="SK_Text">
<%
Dim Atime
Atime=Now()

For J=1 To pop3.count
Set msg = pop3.Messages(J)
mtime = msg.Date

ReTo = "" 
ReCC = "" 
Set Recipients = msg.Recipients
separator = ","
For H= 0 To Recipients.Count - 1
If H= Recipients.Count - 1 Then
separator = ""
End If
Set re = Recipients.item(H) 
If re.ReType = 0 Then 
ReTo = ReTo &re.EMail& separator 
else 
ReCC = ReTo &re.EMail& separator 
End If
Next

set rs1=server.createobject("adodb.recordset")
sql1="select * from SK_OfficeMail where SK_From='"&msg.From&"' and SK_Subject='"&msg.Subject&"' and SK_ReTO='"&ReTo&"' and SK_Type=1"
rs1.open sql1,conn,1,3
if not rs1.eof or not rs1.bof then
else
rs1.AddNew
conn.execute(sql1)
rs1("SK_Type")=1
rs1("SK_FromName")=msg.FromName
rs1("SK_From")=msg.From
rs1("SK_ReTO")=ReTo
rs1("SK_ReCC")=ReCC
rs1("SK_Date")=mtime
rs1("SK_Subject")=msg.Subject
rs1("SK_Body")=msg.HTMLBody
rs1("SK_Read")=0
rs1("SK_Feet")=0
rs1("SK_Del")=0
rs1("SK_SalesID")=Session("UID")
rs1("SK_Time")=Atime
rs1.Update

set rs1=conn.execute("Select SCOPE_IDENTITY()")
GetNewID=rs1(0)

Set Attachments = msg.Attachments
separator = ","
For i = 0 To Attachments.Count - 1
If i = Attachments.Count - 1 Then
separator = ""
End If
Set at = Attachments(i)
at.SaveToFile(""&Server.MapPath(".")&"\Annex\"&""&at.Name)
getAttachments = at.Name
set rs2=server.createobject("adodb.recordset")
sql2="select * from SK_OfficeFiles"
rs2.open sql2,conn,1,3
rs2.AddNew
rs2("SK_Fname")=getAttachments
rs2("SK_Di")="2"
rs2("SK_PID")=GetNewID
rs2.Update
rs2.Close
set rs2=Nothing
Next

rs1.Close
set rs1=Nothing
end if
Next
%>
</td>
</tr>
</table>
</td>
<td width="8" background="../images/tab_15.gif"></td>
</tr>
</table></td>
</tr>
<tr>
<td class="SK_Td_Foot">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1%" height="20"><img src="../images/tab_18.gif" width="12" height="20" /></td>
<td width="98%" class="SK_Td_Page"></td>
<td width="1%"><img src="../images/tab_20.gif" width="16" height="20" /></td>
</tr>
</table>
	
</td>
</tr>
</TBODY>
</table>
</body>
<%
Response.Write"<script>alert('你所接收的邮箱共有" & pop3.count & "封邮件!');this.location.href='SK.MailInbox.asp';</SCRIPT>"
Response.end

else
response.Write "<script LANGUAGE='javascript'>alert('对不起,您的邮箱还没有邮件或者账号设置错误！');window:history.go(-1);</script>"
response.End
end if
pop3.Disconnect
Call CloseDB()
%>
</html>