Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Searching files and email (http://www.go4expert.com/forums/searching-files-email-t21867/)

nazrul10 22Apr2010 17:06

Searching files and email
 
I have couple of files in a folder like below. I like to email all related zip file to each user. Let say userid : ada_lau has 2 file(billing_ada_lau.zip and Trade_ada_lau.zip) and need to email him(ada_lau@yahoo.com) and so on for others.
billing_ada_lau.zip
billing_chan_vi.zip
billing_kai_liu.zip
billing_ted_fox.zip
billing_tony_wu.zip
billing_aj_chase.zip
billing_alan_fox.zip
Trade_ada_lau.zip
Trade_chan_vi.zip
Trade_kai_liu.zip
Trade_ted_fox.zip
Trade_tony_wu.zip
Trade_aj_chase.zip
Trade_alan_fox.zip
I need to pickup each userid and need to see whether this userid belongs to any of the zip filename. If this userid is found any of the zip filename then need to email the zip file. Here is my Code:
Code:

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim userid, email
Dim Subject
Dim TextBody
Dim MessageAttachment
Dim FSO, FLD, FIL
Dim strFolder
Dim ol, ns, newMail

Const ForReading = 1
MessageSubject = "Test Subject"
MessageBody = "Test body"



Set strFolder = "C:\ScotiaBank\History\output_hist_billing"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set FLD = FSO.GetFolder(strFolder)

Set objUserid = FSO.OpenTextFile("C:\ScotiaBank\History\Email\useridmail.txt", ForReading, True)

Do While objUserid.AtEndOfStream <> True
      result = Split( Trim(objUserid.ReadLine), "," )
      userid= result(0) 
      email=result(1)       
      objMessage.To = email

      'If Userid belongs to any zip files name on strFolder then save it into MessageAttachment variabale and finally email it
     
      For Each File In FLD.Files
     
      if UCASE(right(File.Name,13)) = "LETTERPCE.LOG" then
     
      SET MessageAttachment = "c:\attachment.txt"

Loop
'Assume SMTP email server is installed on the machine.
Set objMessage = CreateObject("CDO.Message")

objMessage.Subject = "Subject"

objMessage.TextBody = "Historical data, Status = OK"

objMessage.To = email

  objMessage.Recipients.Add(email)
  objMessage.Attachments.Add(MessageAttachment).Displayname = "Check this out"
  objMessage.Send


Set ol = Nothing
Set objUserid = Nothing
Set FSO = Nothing


shabbir 22Apr2010 23:04

Re: Searching files and email
 
Moved to VB forum


All times are GMT +5.5. The time now is 02:09.