廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 5522 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
rufh 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
初露鋒芒
級別: 初露鋒芒 該用戶目前不上站
推文 x2 鮮花 x96
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[Asp][討論] JMail 的相關說明
檔案名稱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)

%>


以上出處來自於藍色小舖



獻花 x0 回到頂端 [樓 主] From:台灣中華電信 | Posted:2005-10-19 14:05 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.015176 second(s),query:15 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言