WSH脚本中的语法错误

时间:2017-09-14 14:32:15

标签: wsh

我正在写一个脚本tp自动发送一个pdf文件,当它被写入某个文件夹时。 它几乎可以工作,但如果我有一个附件,我会收到语法错误 我把文件的名称作为常量放在代码中,它与附件一起使用。 但是,只要我找到找到的文件的名称,它就不起作用。 这是我的代码。错误是“800401E4 CDO.Message.1”

FOLDER_PDF = "T:\MBö\AusdruckLieferverzug" 
FOLDER_MOVE = "T:\MBö\AusdruckLieferverzug\Sent" 

set lobj_cdomsg = CreateObject("CDO.Message") 
Set objRegEx = CreateObject("VBScript.RegExp")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strPDFs = "" 
For Each file In objFSO.GetFolder(FOLDER_PDF).Files 
    If LCase(objFSO.GetExtensionName(file.Path)) = "pdf" Then 
        strPDFs = """" & file.Path & """"  
    End If 
    lobj_cdomsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    lobj_cdomsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail04.provider.de"
    lobj_cdomsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

    lobj_cdomsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "testperson@firma.de"
    lobj_cdomsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxx"
    lobj_cdomsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465  ' 


    lobj_cdomsg.To = "testperson@apt.de"
    lobj_cdomsg.From = "testperson@apt.de"
    lobj_cdomsg.Subject = "Lieferverzug"
    lobj_cdomsg.TextBody = "Bitte finden Sie als Anlage eine PDF-Datei mit den Artikeln, die im Lieferverzug sind." &  vbCRLF 

    strCmd = "lobj_cdomsg.AddAttachment " &  strPDFs 
    WScript.Echo strCmd
    lobj_cdomsg.AddAttachment strPDFs
    'The following code works but not the code line before, although the content of strPDFs is exactly the same
    'lobj_cdomsg.AddAttachment "T:\MBö\AusdruckLieferverzug\tesdatei.pdf"
    'objFile.Close
    ' Dann ganzes abschicken

    lobj_cdomsg.Configuration.Fields.Update
    lobj_cdomsg.Send
    Set lobj_cdomsg = Nothing

Next 

你能帮我找到错误吗? 提前致谢

1 个答案:

答案 0 :(得分:0)

我发现了错误:

这是命令:   strPDFs =“”“”& file.Path& “”“”

如果我不添加引号,它会起作用。 正确的语法是:strPDFs = file.Path

....    lobj_cdomsg.AddAttachment strPDFs

我希望它对其他人有用。