jmail|jmail 常常要在網站中使用到JMAIL組件來發郵件。乾脆就把常用的功能寫成一個模組,方便調用。
把程式放到一個檔案中,然後包含再call就可以了。(JMAIL4.3)
<%'警告函數
sub w_msg(message,w_to,w_link)
'message是你要彈出的警告資訊,w_to=1表示自動後退一頁,當w_to<>1時w_link表示要跳轉的頁面
if w_to="1" then
%>
<script language="javascript">
<!--
function Index(){ window.alert('<%=message%>');history.back(-1)}
Index();
-->
</script>
<%else%>
<script language="javascript">
<!--
function Index(){ window.alert('<%=message%>');window.location="<%=w_link%>"}
Index();
-->
</script>
<%end if
end sub%>
<%
sub sendmail(mailtitle,mailtext,mailaddress,mailcc,mailbcc,attachment,mailserver)
if mailtitle="" then
mailtitle="系統測試郵件"
end if
if mailtext="" then
mailtext="Just a test"
end if
if mailaddress="" then
call w_msg("郵件地址不可為空","1","")
end if
if mailserver="" then
mailserver="smtp.163.com"
end if
set msg=server.createobject("JMail.Message")
msg.silent = true
msg.logging = true
msg.Charset="GB2312"
msg.ContentType = "text/html"
msg.MailServerUserName="yourusername"
msg.MailServerPassword="yourpassword"
msg.From="youremail"
msg.FromName="dorryyang"
mailaddress_s=split(mailaddress,",") ' 郵件地址用,格開
for i=0 to ubound(mailaddress_s)
msg.AddRecipient trim(mailaddress_s(i))
next
if mailcc<>"" then
mailcc_s=split(mailcc,",")
for i=0 to ubound(mailcc_s)
msg.AddRecipientCC trim(mailcc_s(i))
next
end if
if mailbcc<>"" then
mailbcc_s=split(mailbcc,",")
for i=0 to ubound(mailbcc_s)
msg.AddRecipientBCC trim(mailbcc_s(i))
next
end if
if attachment<>"" then
msg.AddAttachment(attachment) 'attachment寫附件地址
end if
msg.Subject=mailtitle
msg.HTMLBody=mailtext
msg.Send(mailserver)
msg.close
set msg=nothing
call w_msg("發送成功","1","")
end sub
%>