我的下面的脚本将文件的全部内容放在要发送的电子邮件正文中,现在我想通过电子邮件发送我的文件的每一行(我的文件有8列用管道“|”分隔)电子邮件正文模板:
Code:<value in file> Operator:<value in file>
Number:<value in file> Amount:<value in file>
NID:<value in file> Name:<value in file>
DATE:<value in file> HOUR:<value in file>
*****
see the script
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const FileToBeUsed = "C:\link of my file\output.txt\output.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\link of my file\output.txt")
If objFile.Size > 0 Then
Dim objCDO1
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(FileToBeUsed, ForReading)
Set objCDO1 = CreateObject("CDO.Message")
'objCDO1.Textbody = "See the details of the file ."&VbNewLine+vbnewline+vbnewline&"No more details"
'objCDO1.Textbody = f.ReadAll
objCDO1.Textbody = "See the details of the file "&VbNewLine+vbnewline+vbnewline&""&f.ReadAll&""&VbNewLine+vbnewline+vbnewline&"No more details"
objCDO1.AddAttachment("C:\link of my file\output.txt")
f.Close
objCDO1.TO ="adr1@test.com"
objCDO1.From = "adr2@test.com (CCP Stored Procedure Message)"
objCDO1.Subject = "CCP Stored Procedure"
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mysmtp"
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserverport") = 25
objCDO1.Configuration.Fields.Update
objCDO1.Send
Set f = Nothing
Set fso = Nothing
ELSE
Wscript.Echo "no file"
End If
答案 0 :(得分:0)
如果我已正确理解您的问题。
Code:<value in file> Operator:<value in file>
Number:<value in file> Amount:<value in file>
NID:<value in file> Name:<value in file>
DATE:<value in file> HOUR:<value in file>
*****
see the script
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const FileToBeUsed = "C:\link of my file\output.txt\output.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\link of my file\output.txt")
If objFile.Size > 0 Then
Dim objCDO1
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(FileToBeUsed, ForReading)
Set objCDO1 = CreateObject("CDO.Message")
'objCDO1.Textbody = "See the details of the file ."&VbNewLine+vbnewline+vbnewline&"No more details"
'objCDO1.Textbody = f.ReadAll
strFileText = f.ReadAll
f.Close
arrFileText = Split(strFileText, vbcrLF) 'split the file content by line feed character
For intArrCounter = 0 to uBound(arrFileText)
ArrLineContent = Split(arrFileText(intArrCounter)),"|")
Code = ArrLineContent(0)
Operator = ArrLineContent(1)
&#39;为所有剩余列创建变量。在文本主体中按照自己喜欢的方式使用它们。
objCDO1.Textbody = "See the details of the file"&VbNewLine+vbnewline+vbnewline&""&arrFileText(intArrCounter)&""&VbNewLine+vbnewline+vbnewline&"No more details"
objCDO1.AddAttachment("C:\link of my file\output.txt")
objCDO1.TO ="adr1@test.com"
objCDO1.From = "adr2@test.com (CCP Stored Procedure Message)"
objCDO1.Subject = "CCP Stored Procedure"
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mysmtp"
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserverport") = 25
objCDO1.Configuration.Fields.Update
objCDO1.Send
Next
Set f = Nothing
Set fso = Nothing
ELSE
Wscript.Echo "no file"
End If
您可能需要对此进行一些调试。