none
Help with email script RRS feed

  • Question

  • I am trying to create a script that will automatically send an email with information contained in a text file and the name of the text file changes daily based on the date. Currently the script is just sending the attachment and I couldn't figure out how to use a wildcard to change the name of the file daily. Any help would be appreciated. Thank you in advance!

    Dim ToAddress
    Dim FromAddress
    Dim MessageSubject
    Dim MyTime
    Dim MessageBody
    Dim MessageAttachment
    Dim ol, ns, newMail
    MyTime = Now

    ToAddress = "email@email"
    MessageSubject = "Subject line"
    MessageBody = "See attachment" 
    MessageAttachment = "I:\Check 21 Report_*.txt"
    Set ol = WScript.CreateObject("Outlook.Application")
    Set ns = ol.getNamespace("MAPI")
    Set newMail = ol.CreateItem(olMailItem)
    newMail.Subject = MessageSubject
    newMail.Body = MessageBody & vbCrLf & MyTime
    newMail.RecipIents.Add(ToAddress)
    newMail.Attachments.Add(MessageAttachment)
    newMail.Send

    Thursday, April 24, 2014 6:54 PM

Answers

  • There are (almost) no wildcards in VBScript. You need to obtain the file name yourself, using code like this:

    sFolder = "I:\"
    Set oFSO = WScript.CreateObject("Scripting.Filesystemobject")
    Set oFolder = oFSO.GetFolder(sFolder)
    ForEach oFile In oFolder.Files
        WScript.Echo oFile.Path
    Next

    Have a look at script56.chm (downloadable from the Microsoft site) and at the script repository in order to find out more about the file system object.

    Thursday, April 24, 2014 8:10 PM