2012年8月8日 星期三

[VBSCRIPT]使用CDO物件來寄EMail

Set objCDO = CreateObject("CDO.Message")
  strCfg = "http://schemas.microsoft.com/cdo/configuration/"
 With objCDO

 .Sender = "此處為寄件者的顯示名稱,ex:賈斯汀"

 .From = "賈斯汀@gmail.com"
  .To = "瑪麗亞@gmail.com"
 .Fields("urn:schemas:mailheader:X-Priority") = 1 ' Priority = PriorityUrgent 高優先順序
  .Fields("urn:schemas:mailheader:return-receipt-to") = "誰是寄件者@NoOneKnows.com" ' 要求讀取回條
  ' .Fields("urn:schemas:httpmail:importance") = 2 ' Importance = High
  ' .Fields("urn:schemas:httpmail:priority") = 1 ' Priority = PriorityUrgent
  .Fields.Update ' 更新欄位
  .Subject = "沒有主旨(放主題啦)"
 ' Text 文字格式信件內容
  .TextBody = "ORZ"
  ' 或 HTML 網頁格式信件內容
  .HTMLBody = "<HTML>" & _
         "<BODY>" & _
           "<table border=""1"" width=""100%"">" & _
             "<tr><td>I</td><td>am</td><td>Hammer</td><td>!</td></tr>" & _
             "<tr><td>Who</td><td>r</td><td>u</td><td>?</td></tr>" & _
           "</table>" & _
         "</BODY>" & _
       "</HTML>"
  .AddAttachment "C:\AttFile.zip" ' 附加檔案
  .CC = "Xman@yahoo.com.tw"   ' 副本
 .BCC = "SpiderMan@hotmail.com.tw" ' 密件副本
  .Configuration(strCfg & "sendusing") = 2 ' Sendusing = SendUsingPort
  .Configuration(strCfg & "smtpserver") = "msa.hinet.net" ' SMTP Server
  ' .Configuration(strCfg & "smtpserverport") = 25 ' SMTP Server Port ( 預設即為 25 )
  ' SMTP Server 如需登錄 , 則需設定 UserName / Password
  ' .Configuration(strCfg & "sendusername") = "UserName" ' Send User Name
  ' .Configuration(strCfg & "sendpassword") = "Password" ' Send Password
  .Configuration.Fields.Update ' 更新 (欄位) 組態
  ' .DSNOptions = 4 ' 回傳信件傳送狀態
  '  cdoDSNDefault = 0 , DSN commands are issued.
  '  cdoDSNDelay = 8 , Return a DSN if delivery is delayed.
  '  cdoDSNFailure = 2 , Return a DSN if delivery fails.
  '  cdoDSNNever = 1 , No DSNs are issued.
  '  cdoDSNSuccess = 4 , Return a DSN if delivery succeeds.
  '  cdoDSNSuccessFailOrDelay = 14 ,Return a DSN if delivery succeeds, fails, or is delayed.
  .Send ' 傳送
End With
Set objCDO = Nothing

沒有留言:

張貼留言