Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vb Script email attachment with multiple files

Status
Not open for further replies.

Nirvan

IS-IT--Management
Oct 9, 2018
1
US
I need your help. I have to attach 2 files to an email but I can only do so with one with the current script.
Also the file names are specific hence the sFileNameStart and sFileNameEnd
2 file names are
KFC_EL_20181009_R181009041923.100001_271_I.xls
KFC_IE_20181009_R181009041923.100001_271_IP.xls



Const startDir = "C:\scripts\blah"
Set oFSO = CreateObject("Scripting.FileSystemObject")
DateToday = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2)
sFileNameStart = "KFC" & DateToday
sFileNameEnd = ".xls"
Set objEmail = CreateObject("CDO.Message")
Set oFolder = oFSO.GetFolder(startDir)
sFullFileName = ""
Recurse oFolder
If sFullFileName <> "" Then
sendEmail
Else
WScript.Echo "No File Exists."
End If

Sub Recurse(oFldr)
For Each oSubFolder In oFldr.SubFolders
Recurse oSubFolder
Next
For Each oFile In oFldr.Files
If Left(LCase(oFile.Name), Len(sFileNameStart)) = LCase(sFileNameStart) And _
Right(LCase(oFile.Name), Len(sFileNameEnd)) = LCase(sFileNameEnd) Then
sFullFileName = oFile.Name
Exit Sub
End If
Next
End Sub

Sub sendEmail()
objEmail.From = "blah@blah.org"
objEmail.To = "blah@blah.org"
objEmail.Subject = "Daily blah Files"
objEmail.Textbody = "Please see attached for today's files."
objEmail.AddAttachment startDir & "\" & sFullFileName
With objEmail.Configuration.Fields
.Item(" = 2
.Item(" = "blah.blah1.org" ' Mail Server to use for SMTP"
.Item(" = 25
.Update
End With
objEmail.Send
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top