档案名称EMail.asp放在INC/中
INC/EMail.asp
<%
Function SendMail(Subject,Sender,SenderName,Recipient,bodytxt,Attachment,RecipientCC,RecipientBCC)
'************************************************************
' 撰写者:TOPCAT 撰写日期:2001/11/29
' 功能:用来传送电子邮件的INCLUDE
' 参数说明:
' Subject : string 传入信件的主旨
' Sender : string 传入寄件者的电子邮件
' SenderName : string 传入寄件者的名称
' Recipient : Array 传入收件者的电子邮件
' bodytext : string 传入信件内容
' Attachment : Array 传入附加档案的绝对路径
' RecipientCC : Array 传入副本的电子邮件
' RecipientBCC : Array 传入隐藏副本的电子邮件
' 程式说明:
'*************************************************************
Set JMail=Server.CreateObject("JMail.SMTPMail")
JMail.Subject = Subject
'JMail.ContentType = "txt/html"
JMail.Charset = "big5"
'JMAIL.ContentTransferEncoding = "base64"
JMAIL.Encoding = "base64"
JMAIL.ISOEncodeHeaders = false
JMail.Sender = Sender
JMail.SenderName = SenderName
Dim x
For x = 1 to UBound(Recipient)
JMail.AddRecipient(Recipient(x))
Next
If IsArray(RecipientCC) Then
For k = 1 to UBound(RecipientCC)
JMail.AddRecipientCC(RecipientCC(k))
Next
End If
If IsArray(RecipientBCC) Then
For l = 1 to UBound(RecipientBCC)
JMail.AddRecipientBCC(RecipientBCC(l))
Next
End If
If IsArray(Attachment) Then
For j = 1 to UBound(Attachment)
JMail.AddAttachment(Attachment(j))
Next
End If
JMail.ServerAddress = "msa.hinet.net" '请在此变更您的送件邮件伺服器
JMail.Silent = true
JMail.Body = bodytxt
MailRC=JMail.Execute()
set JMail=nothing
SendMail = "Success"
End Function
Function HTMLSendMail(Subject, Sender, SenderName, Recipient, bodytxt, Attachment, RecipientCC, RecipientBCC, HTMLBody)
'************************************************************
' 撰写者:TOPCAT 撰写日期:2005/03/29
' 功能:用来传送电子邮件的INCLUDE
' 参数说明:
' Subject : string 传入信件的主旨
' Sender : string 传入寄件者的电子邮件
' SenderName : string 传入寄件者的名称
' Recipient : Array 传入收件者的电子邮件
' HTMLBody : string 传入信件内容(HTML)
' Attachment : Array 传入附加档案的绝对路径
' RecipientCC : Array 传入副本的电子邮件
' RecipientBCC: Array 传入隐藏副本的电子邮件
' 程式说明:
'*************************************************************
Set JMail = Server.CreateObject("JMail.Message")
JMail.Subject = Subject
JMail.Charset = "big5"
JMail.Encoding = "base64"
JMail.ISOEncodeHeaders = False
JMail.ReplyTo = Sender
JMail.From = Sender
JMail.FromName = SenderName
Dim x
For x = 1 To UBound(Recipient)
JMail.AddRecipient Recipient(x)
Next
If IsArray(RecipientCC) Then
For k = 1 To UBound(RecipientCC)
JMail.AddRecipientCC RecipientCC(k)
Next
End If
If IsArray(RecipientBCC) Then
For l = 1 To UBound(RecipientBCC)
JMail.AddRecipientBCC RecipientBCC(l)
Next
End If
If IsArray(Attachment) Then
For j = 1 To UBound(Attachment)
JMail.AddAttachment (Attachment(j))
Next
End If
JMail.Silent = True
JMail.Body = bodytxt
HTMLBody = "<style>.dl{font-size:12;}.dh{font-size:14;background-color:blue;color:yellow}"
HTMLBody = HTMLBody & ".dt{font-size:16;background-color:DarkBlue;color:yellow}</style><html "
HTMLBody = HTMLBody & "bgcolor=LightCyan><body><table width=750 border=0 bgcolor=LightCyan><tr>"
HTMLBody = HTMLBody & "<td class=dl>" & HTMLBody & "</td></tr></table></body></html>"
JMail.HTMLBody = HTMLBody
MailRC = JMail.Send("msa.hinet.net") '请在此变更您的送件邮件伺服器
Set JMail = Nothing
HTMLSendMail = MailRC
End Function
%>
接着,就来看一下如何的使用Include中的两个Function
如果您安装的是旧版的JMail
那么请使用第一个Function
寄信的内容只能是一般的【文字方式】
方式如下
<!--#include file="INC/EMail.asp" -->
<%
Subject="信件的主旨"
Sender="
abc@msa.hinet.net" '寄信者EMail
SenderName="送件者姓名"
Dim Recipient(3) '假设收件者有3人
Recipient(1) = "
111@ms1.hinet.net"
Recipient(2) = "
222@ms2.hinet.net"
Recipient(3) = "
333@ms3.hinet.net"
bodytxt = ""
Bodytxt = Bodytxt & " 您可以在此 " & chr(13) & Chr(10)
Bodytxt = Bodytxt & " 输入您的信件内容 " & chr(13) & Chr(10)
Bodytxt = Bodytxt & " " & chr(13) & Chr(10)
Dim Attachment(2) '设定附件,假设有2个
Attachment(1) = "D:\Fiels\Excel1.xls"
Attachment(2) = "D:\Fiels\Excel1.xls"
Dim RecipientCC(2) '设定副本收件人有2人
RecipientCC(1) = "
444@ms4.hinet.net"
RecipientCC(2) = "
555@ms5.hinet.net"
'RecipientBCC 假设没有密件副本
rc=SendMail(Subject,Sender,SenderName,Recipient,bodytxt,Attachment,RecipientCC,RecipientBCC)
%>
只需要设定这些参数,就能够将信寄出
如果安装的版本是JMail4.2以后的版本
就能够支援HTML的信件内容
如果您的信需要较多的排版(比如说购物车内容)
就可以使用新的方式,寄出HTML的内容
范例如下
<!--#include file="INC/EMail.asp" -->
<%
Subject="信件的主旨"
Sender="
abc@msa.hinet.net" '寄信者EMail
SenderName="送件者姓名"
Dim Recipient(3) '假设收件者有3人
Recipient(1) = "
111@ms1.hinet.net"
Recipient(2) = "
222@ms2.hinet.net"
Recipient(3) = "
333@ms3.hinet.net"
'bodytxt = ""
'Bodytxt = Bodytxt & " 您可以在此 " & chr(13) & Chr(10)
'Bodytxt = Bodytxt & " 输入您的信件内容 " & chr(13) & Chr(10)
'Bodytxt = Bodytxt & " " & chr(13) & Chr(10)
HTMLBody=""
HTMLBody=HTMLBody & " "
HTMLBody=HTMLBody & " "
HTMLBody=HTMLBody & " <table border=1 bgcolor=pink> "
For y = 1 to 5
HTMLBody=HTMLBody & " <tr> "
For x = 1 to 6
HTMLBody=HTMLBody & " <td class=dl>X:" & x & ",Y:" & y & "</td> "
Next
HTMLBody=HTMLBody & " </tr> "
Next
HTMLBody=HTMLBody & " </table> "
Dim Attachment(2) '设定附件,假设有2个
Attachment(1) = "D:\Fiels\Excel1.xls"
Attachment(2) = "D:\Fiels\Excel1.xls"
Dim RecipientCC(2) '设定副本收件人有2人
RecipientCC(1) = "
444@ms4.hinet.net"
RecipientCC(2) = "
555@ms5.hinet.net"
'RecipientBCC 假设没有密件副本
rc=HTMLSendMail(Subject, Sender, SenderName, Recipient, bodytxt, Attachment, RecipientCC, RecipientBCC, HTMLBody)
%>
以上出处来自于蓝色小铺