-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