我正在寫一個VBScript來在文件到達Test文件夾時發送電子郵件通知。我想將該文件附加到我的電子郵件中。文件名稱不是恆定的。每次文件以不同的名稱到達時。發送帶附件的電子郵件通知
下面是我的代碼:
Const PATH = "F:\Test"
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim folder: Set folder = fso.GetFolder(PATH)
If folder.Files.Count <> 0 Then
strSMTPFrom = "[email protected]"
strSMTPTo = "[email protected]"
strSMTPRelay = "127.0.0.1"
strTextBody = "The attached file arrived in Test folder"
strSubject = "File arrived in Test folder"
strAttachment =
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment
oMessage.Send
End If
另外,你的問題是什麼?你不確定如何附加文件?你的代碼的其餘部分是否工作?你有錯誤信息嗎?你有沒有嘗試過一些方法來附加文件? – vacip
我想將文件附加在文件夾內 –
試過了,它不起作用 –