How do I attach multiple files to Mail?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rohithcs
    New Member
    • Nov 2007
    • 5

    How do I attach multiple files to Mail?

    I need a piece of code which could attach all the files stored in a folder.
    The files in the folder can be *.xls, *.doc or *.pdf. I will be having only the path of the folder and file names in the folder would be dynamic.
    Can anyone help me out?
  • Tequilaman
    New Member
    • Oct 2007
    • 43

    #2
    What about calling an open file box for the path with verification on the file name extensions? In case you need you can disable attachments from different path as well. Still in that path you will let the user decide about attaching the file(s).

    Or do you want to automate upload, sending etc.? - Using a batch lying in that path for the choice might still be an alternative.
    Last edited by Killer42; Nov 13 '07, 02:29 AM.

    Comment

    • rohithcs
      New Member
      • Nov 2007
      • 5

      #3
      Originally posted by Tequilaman
      What about calling an open file box for the path with verification on the file name extensions? In case you need you can disable attachments from different path as well. Still in that path you will let the user decide about attaching the file(s).

      Or do you want to automate upload, sending etc.? - Using a batch lying in that path for the choice might still be an alternative

      Thanks for your reply.
      I want to automate the upload. The path of the folder is fixed. And I would like to attach all the files in the folder.

      Could please help me out?
      Last edited by Killer42; Nov 13 '07, 02:30 AM.

      Comment

      • Tequilaman
        New Member
        • Oct 2007
        • 43

        #4
        I would just select by " *.* " in the path using the ancient DOS routine. - Hoping you don't use VISTA, in XP it still works.

        For that you need to specify the path like " X:\tempor~1\*.* " - I have had some trouble with the long file (directory) names when transfering progs. Using 8 char should be better to keep it from crashing

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          I think to give any useable advice we need more detail about what you are doing now, in what version of VB. Selecting all the files in a folder in VB is very simple, but the details will vary a bit between versions. And presumably, attaching them to an e-mail will depend on how you are creating the e-mail.

          Comment

          • rohithcs
            New Member
            • Nov 2007
            • 5

            #6
            Originally posted by Killer42
            I think to give any useable advice we need more detail about what you are doing now, in what version of VB. Selecting all the files in a folder in VB is very simple, but the details will vary a bit between versions. And presumably, attaching them to an e-mail will depend on how you are creating the e-mail.

            Here is detail requirement.
            Requirement: With cllck of a button. I would like to send a mail and attach the files in a particular folder.

            Code:
            Private Sub Form_Load()
            Dim Olook As Object
            Dim Omail As Object
            Set Olook = CreateObject("O utlook.Applicat ion")
            Set Omail = Olook.CreateIte m(olMailItem)

            MailBody = "Hi ,"
            Mail1Body = " Find attached the documents ,"

            Omail.To = "new@yahoo.co.i n"
            Omail.Subject = "Find documents "
            Omail.Body = MailBody & vbCrLf & vbCrLf & Mail1Body & EndOfMail

            Omail.Display:

            Unload Me
            End Sub


            Problem:
            with the above code i am able to compose the mail. I am not sure how to attach files to this mail.

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

              Take a Look at this M$ Article:
              Outlook Attachment

              Regards
              Veena

              Comment

              • rohithcs
                New Member
                • Nov 2007
                • 5

                #8
                Originally posted by QVeen72
                Hi,

                Take a Look at this M$ Article:
                Outlook Attachment

                Regards
                Veena
                Thanks for your support.
                I looked into the article in the mentioned link.
                The code works fine, if you know the filename.

                what if the filename keeps changing? (Although path remains the same)

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Hi,

                  Place a "File List Box" on the Form, and Change the Path of that and Refresh it. FileListBox will be populated with all the Files in that Folder..
                  Loop through the List Items (as any Normal ListBox) and it should be done..

                  some thing like this :

                  [code=vb]
                  Dim MyFileName As String
                  Dim i As Integer
                  File1.Path = "C:\MyFolde r"
                  File1.Refresh
                  For i = 0 To File1.ListCount-1
                  MyFileName = File1.Path & "\" & File1.List(i)
                  ' MyFile Name is the File Name in that Folder
                  ' Write Your Attachment Code here
                  Next
                  [/code]


                  Regards
                  Veena

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Since it looks as though you're using VB6, it's also quite simple to use the Dir() function to retrieve file names. For example, to read all the filenames in the folder Veena used...

                    [CODE=vb]Dim FileName As String
                    FileName = Dir("C:\MyFolde r") ' Find first matching file.
                    Do While FileName <> ""
                    Debug.Print FileName
                    FileName = Dir ' No parameters. Just gets next match.
                    Loop[/CODE]The advantage of this is that it's quick and simple. It doesn't require a form, a control, or (as the FileSystemObjec t would) any extra references.

                    Comment

                    Working...