1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Searching files and email

Discussion in 'Visual Basic ( VB )' started by nazrul10, Apr 22, 2010.

  1. nazrul10

    nazrul10 New Member

    Joined:
    Apr 22, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
    Last edited by a moderator: Apr 22, 2010
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Moved to VB forum
     

Share This Page