Ulysses 打了個電話來問: 『在 VB 裡要怎麼作 sendmail 的功能?』剛好以前作的專案有這麼一段 Sample Code,就貼上來了。本來這段 Code 是給 ASP 用的,所以要在 VB 上使用可能要作一些小修改。另,原註解部分沒有移除,以方便修改需要。
‘ Create an instance of the NewMail object.
Set objCDOMail = Server.CreateObject(“CDONTS.NewMail”)
‘ This syntax works fine
‘objCDOMail.From = “[email protected]”
objCDOMail.From = “User Name
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.Body = strBody
‘ Some of the more useful ones I’ve included samples of here:
‘objCDOMail.Cc = “[email protected];[email protected]”
‘objCDOMail.Bcc = “[email protected];[email protected]”
‘objCDOMail.Importance = 1 ‘(0=Low, 1=Normal, 2=High)
‘objCDOMail.AttachFile “c:\path\filename.txt”, “filename.txt”
‘ I’ve had several requests for how to send HTML email.
‘ To do so simply set the body format to HTML and then
‘ compose your body using standard HTML tags.
‘objCDOMail.BodyFormat = 0 ‘ CdoBodyFormatHTML
‘Outlook gives you grief unless you also set:
‘objCDOMail.MailFormat = 0 ‘ CdoMailFormatMime
‘ THIS LINE SHOULD BE UNCOMMENTED TO ACTUALLY SEND THE
‘ MESSAGE. PLEASE BE SURE YOU HAVE APPROPRIATE VALUES
‘ FOR TO AND FROM ADDRESSES AND HAVE CHANGED THE MESSAGE
‘ SUBJECT AND BODY BEFORE UNCOMMENTING THIS.
‘ Send the message!
objCDOMail.Send
‘ Set the object to nothing
Set objCDOMail = Nothing