<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" -->
<%if Not (getconfig("SK_Office")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK100000000") AND JudgePopedomTF(Session("UserName"),"SK100000703")))) then Call ReturnError()%>
<%
Server.ScriptTimeOut=5000
Dim Anum:Anum=5
'AddNew
if RQ("Action")="Send" and F("S_ToEmail")<>"" and F("S_Title")<>"" and F("S_Content")<>"" then
Call ChkIsOuter()

'读取SMTP相关信息
set rs1=Server.CreateObject("ADODB.Recordset")
sql1="select * from SK_SystemUsers where UsersID ="&Session("UID")&""
rs1.open sql1,conn,1,1
smtpserver =rs1("SK_Smtp")'发送邮件所使用的SMTP服务器
smtpuser =rs1("SK_Mailname") '与SMTP服务器对应的邮箱用户名
smtppwd =rs1("SK_Mailpass") '与SMTP服务器对应的邮箱密码
smtpemail =rs1("SK_Mailname")  'SMTP服务器发信邮箱
Replyemail=rs1("SK_MailName") '回复的邮箱
Sign=rs1("SK_Maxim") '个性签名

'发送的相关信息
set jmail= server.CreateObject ("jmail.message")
jmail.Silent = true
jmail.Charset = "gb2312"
jmail.Encoding= "base64 "
jmail.From = smtpemail '发送的邮箱
jmail.FromName = F("S_MyName") '发件人姓名
jmail.ReplyTo = Replyemail '回复的邮箱
jmail.Subject = F("S_Title") '发送的主题
faemail=split(F("S_ToEmail"),",") '收件人信箱
for i=0 to UBound(faemail)
JMail.AddRecipient Trim(faemail(i))

set rs3=server.createobject("adodb.recordset")
sql3="select * from SK_OfficeMail"
rs3.open sql3,conn,3,3
rs3.AddNew
rs3("SK_ReTO")=faemail(i)

next
jmail.Body = F("S_Content") '邮件内容

for u=1 to Anum
JMail.ContentType= "multipart/related" '有附件时一定要使用此行代码
JMail.AddAttachment(""&Server.mappath(""&F("fj"&u)&"")&"") '邮件附件
JMail.ContentType = "text/html" '没有附件时显示页面内容
next

JMail.appendText "<P>-----------------------------------------<BR>"&Sign&"<BR>-----------------------------------------"
jmail.AddRecipientCC F("S_ReCC")   '邮件抄送者的地址
jmail.AddRecipientBCC F("S_ReBCC")   '密件收件人的地址 
jmail.Priority = 1 '邮件发送等级
jmail.ReturnReceipt = True '是否需要回执
jmail.MailServerUserName = smtpuser 'SMTP服务器用户名
jmail.MailServerPassWord = smtppwd 'SMTP服务器密码
isgo = jmail.Send(smtpserver)  'SMTP服务器

rs3("SK_ReCC")=F("S_ReCC")
rs3("SK_BCC")=F("S_ReBCC")
rs3("SK_From")=Replyemail
rs3("SK_FromName")= F("S_MyName")
rs3("SK_Type")=0
rs3("SK_Subject")=F("S_Title")
rs3("SK_Body")=F("S_Content")
rs3("SK_Date")=Now()
rs3("SK_Time")=Now()
rs3("SK_SalesID")=Session("UID")
rs3("SK_Read")="0"
rs3("SK_Feet")="0"
rs3("SK_Class")="0"
rs3("SK_Del")="0"

if isgo then
msg="恭喜您,邮件发送成功!"
rs3("SK_Success")=0
set rs5=server.createobject("adodb.recordset")
sql5="select * from SK_OfficeMail where ID="&F("ReID")&""
rs5.open sql5,conn,1,3
conn.execute(sql5)
rs5("SK_Read")=2
rs5.Update
rs5.Close
Set RS5=Nothing
else
msg = "邮件发送失败,以下为出错原因！\r\n\r\n\一、收件人邮箱错误\r\n\r\n\二、SMTP相关配置有问题，或者该SMTP服务器不支持\r\n\r\n\三、可能是短时间发送太多邮件，SMTP临时关闭了。"
rs3("SK_Success")=1
end if
rs3.Update

set rs3=conn.execute("select @@IDENTITY")
GetNewID=rs3(0)

for T=1 to Anum
if F("fj"&T)<>"" then
set rs1=server.createobject("adodb.recordset")
sql1="select * from SK_OfficeFiles"
rs1.open sql1,conn,1,3
rs1.AddNew
rs1("SK_Di")="2"
rs1("SK_PID")=GetNewID
rs1("SK_Fname")=F("fj"&T)
rs1("SK_ATime")=Now()
rs1("SK_Down")="0"
rs1.Update
rs1.Close
end if
next

jmail.Close
set jmail = nothing
Response.write "<script>alert('系统提示：\r\n\r\n\"&msg&"');location.href='SK.SendMail.asp'</script>"
response.end

end if
%>
<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 language="javascript">
window.onbeforeunload = function()
{
if (document.body.offsetWidth-50 < event.clientX && event.clientY<0)
{
return "是否关闭当前窗口？关闭本窗口将放弃发送邮件！";
}
}

function Form1_Validator(theForm)
{ 
if (theForm.S_ToEmail.value == "")
{
alert("对不起,收件人不能为空!");
theForm.S_ToEmail.focus();
return (false);
}

if (theForm.S_Title.value == "")
{
alert("对不起,主题不能为空!");
theForm.S_Title.focus();
return (false);
}

return (true);
}
function showUploadDialog(s_Type, s_Link, s_Thumbnail){
var arr = showModalDialog("<%=getconfig("SK_EditorPath")%>/dialog/i_upload.htm?style=mini&type="+s_Type+"&link="+s_Link+"&thumbnail="+s_Thumbnail, window, "dialogWidth:0px;dialogHeight:0px;help:no;scroll:no;status:no");
}
</script>
<style type="text/css">
<!--
body {
margin: 5px 0px 5px 0px;
overflow-x: hidden;
}
ul,li{ margin:0; padding:0; list-style:none}
ul{ padding:1px; border:0px;}
li { border-bottom:1px dashed #eee; padding:4px}
-->
</style>
</head>
<body>
<table width="99%" 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 width="8" background="../images/tab_12.gif"></td>
<td>

<form id="form1" name="thisForm" method="post" action="?Action=Send" onSubmit="return Form1_Validator(this)">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">
<tr>
  <td width="13%" class="SK_Text2">收件人</td>
  <td width="87%" colspan="5" class="SK_Text1">
<%
Dim str
if F("Action")="QF" then
set RsClient=server.createobject("adodb.recordset")

if F("id")<>"" then
SqlClient="select * from SK_Linkman where LinkmanID in("&F("id")&")"
else
SqlClient="select * from SK_Linkman"
end if

RsClient.open SqlClient,conn,1,1
do while not RsClient.eof
if RsClient("SK_Email")<>"" then
str = str &RsClient("SK_Email")&","
end if
RsClient.movenext
loop
'循环出来后减去最后那个逗号
str = mid(str,1,len(str) -1 )
'Response.Write(""&str&"")
RsClient.close
set RsClient=Nothing
%>
<input name="S_ToEmail" type="text" size="50" value="<%=""&str&""%>">
<%else%>
<input name="S_ToEmail" type="text" size="50" value="<%=F("Reto")%>"> 
<%end if%>
  <font color=red>*发送多人，邮箱间用逗号隔开(注意要在半角下面的符号)。</font></td>
</tr>
<tr>
  <td class="SK_Text2">抄　送</td>
  <td colspan="5" class="SK_Text1"><input name="S_ReCC" type="text" size="50"></td>
</tr>
<tr>
  <td class="SK_Text2">暗　送</td>
  <td colspan="5" class="SK_Text1"><input name="S_ReBCC" type="text" size="50"></td>
</tr>
<tr>
  <td class="SK_Text2">名　称</td>
  <td colspan="5" class="SK_Text1"><input name="S_MyName" type="text" size="20" value="<%=Session("UserName")%>" ></td>
</tr>
<tr>
  <td class="SK_Text2">主　题</td>
  <td colspan="5" class="SK_Text1"><input name="S_Title" type="text" size="40" value="<%=F("Subject")%>"> <font color=red>*</font></td>
</tr>


<tr>
  <td valign="top" class="SK_Text2">内　容</td>
  <td colspan="5" class="SK_Text1"><IFRAME ID="eWebEditor1" SRC="<%=getconfig("SK_EditorPath")%>/ewebeditor.htm?id=S_Content&style=mini" FRAMEBORDER="0" SCROLLING="no" WIDTH="600" HEIGHT="300"></IFRAME>
<input type="hidden" name="S_Content" value="<%=F("ReContent")%>"> <font color=red>*</font></td>
</tr>

<tr>
  <td valign="top" class="SK_Text2">附件</td>
  <td colspan="5" class="SK_Text1">
<%for L=1 to Anum%>
<input type="text" name="fj<%=L%>" id="fj<%=L%>" size="40" readonly/> <input type="button" value="上传" class="button1" onClick="showUploadDialog('file', 'thisForm.fj<%=L%>', '')" /><br>
<%next%></td>
</tr>

<tr>
  <td valign="top" class="SK_Text2">环境支持</td>
  <td colspan="5" class="SK_Text1"><%If IsObjInstalled("JMail.Message") or IsObjInstalled("JMail.SMTPMail") Then%>
<img src="../images/yes.gif" />
<%else%>
<img src="../images/no.gif" /> <a href="http://www.skcrm.com/jmail.rar" target="_blank">下载组件</a>
<%end if%></td>
</tr>

<tr>
<td colspan="6" class="SK_Text">
<INPUT class="button1" type="submit" value=" 确定 "> 
<%if F("Subject")<>"" OR F("ID")<>"" OR F("Action")="QF" then%>
<input type="button" value=" 返回 " onClick="history.go(-1);" class="button1">
<input type="hidden" name="ReID" value="<%=F("Reid")%>">
<%else%>
<input type="button" value=" 关闭 " onClick="window.opener.location.reload();window.close();" class="button1" />
<%end if%></td>
</tr>
</table>
</form>
</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>
<%
Call CloseDB()
%>
</html>