-1
我使用以下腳本在白天發送一些電子郵件,它需要一個或多個參數(有幾個版本),並由.bat文件調用。該腳本是:VBscript - 文本文件正文到電子郵件
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 2
Const cdoSendUsingPort = 2
Dim oMsg, oConf
Dim sDateTimeStamp
Set args = WScript.Arguments
arg1 = args(0)
' E-mail properties
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "[email protected]" ' or "Sender Name <[email protected]>"
oMsg.To = "[email protected]" ' or "Recipient Name <[email protected]>"
oMsg.Subject = "System Message"
oMsg.BodyPart.Charset = "Windows-1253"
oMsg.Textbody = "Attached files." & vbcrlf & _
"This on a new line" & vbcrlf & _
"This on yet another"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const FileToBeUsed = "DIRTEST.TXT"
Dim fso, f, g
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(FileToBeUsed, ForReading)
g = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "gmail.com" 'server address
oConf.Fields(schema & "smtpserverport") = 587 'port number
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic 'authentication type
oConf.Fields(schema & "smtpusessl") = False 'use SSL encryption
oConf.Fields(schema & "sendusername") = "[email protected]" 'sender username
oConf.Fields(schema & "sendpassword") = "XXXXXX" 'sender password
oConf.Fields.Update()
'base64
' send message
oMsg.Send()
' Return status message
If Err Then
resultMessage = "ERROR " & Err.Number & ": " & Err.Description
Err.Clear()
Else
resultMessage = "Success Notification Message sent succesfully."
End If
Wscript.echo(resultMessage)
現在文本主體設置爲:
Attached Files
This is a new line
This is yet another
我想插線1和2之間的目錄列表,直接或通過保存列出目錄一個文本文件,然後把所述文件的內容在電子郵件正文中,像這樣:
Attached Files
06/10/2016 <TIME> 13.000 Name1.txt
06/10/2016 <TIME> 300.000 Name2.pdf
06/10/2016 <TIME> 150.000 Name3.pdf
06/10/2016 <TIME> 5.000.000 Name4.pdf
This is a new line
This is yet another
編輯:上面的代碼成功地追加目錄列表,郵件主題,而且還附加了一個BATC h的亂碼字符在頂部。
所以你有沒有嘗試過放置目錄列表,代碼在哪裏呢?......我們不需要看到所有這些。請參閱提供[mcve]。 – Lankymart
如果我知道如何去做,我顯然不需要問。 – onlyf
雖然我問你是否有*「嘗試」*,但還是有區別的。理想情況下,需要表明*提問者努力解決問題的努力程度,並伴隨[mcve]顯示他們到達的具體問題以及他們遇到的具體問題*(錯誤消息等)*。目前這既不滿足,也可能會被視爲「太廣泛」。 – Lankymart