Solved

Save Attachments From the Outlook Express Inbox to a File

Posted on 2001-06-28
21
529 Views
Last Modified: 2007-11-27
Dear experts,
This is my problem :
I want to save every attachments in my Outlook Express inbox (with certain email subject) to a file in a certain directory.

So far, I can only do this using Micr. Outlook, not Outlook Express (I use Micr. Outlook 9.0 Object Lib as my VB project - reference), although my default mail client is Outlook Express.

FYI, I use VB 6.0, Outlook Express 5

Your help will be very much appreciated.
Thank you in advance :-)

Rgds,
Kiky
0
Comment
Question by:kiky
  • 8
  • 7
  • 3
  • +2
21 Comments
 
LVL 1

Expert Comment

by:wongchun
Comment Utility
I think you can try CDO or MAPI to do this.

Daniel
0
 

Author Comment

by:kiky
Comment Utility
Hi wongchun,
Thanks for your reply.
I'm sorry, I'm very new in VB, so would you mind to explain it more detail ? :-)

How do I program this CDO / MAPI with VB so I can access to Outlook Express and save my mail attachments in my Outlook Exp inbox ?

Rgds,
Kiky Tan

0
 

Author Comment

by:kiky
Comment Utility
Hi wongchun,
Thanks for your reply.
I'm sorry, I'm very new in VB, so would you mind to explain it more detail ? :-)

How do I program this CDO / MAPI with VB so I can access to Outlook Express and save my mail attachments in my Outlook Exp inbox ?

Rgds,
Kiky Tan

0
 

Author Comment

by:kiky
Comment Utility
Hi wongchun,
Thanks for your reply.
I'm sorry, I'm very new in VB, so would you mind to explain it more detail ? :-)

How do I program this CDO / MAPI with VB so I can access to Outlook Express and save my mail attachments in my Outlook Exp inbox ?

Rgds,
Kiky Tan

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Go to project, references and set a reference to Outlook expresss type library.
Use it like any other object.
If you need explicit code, let me know.
0
 

Author Comment

by:kiky
Comment Utility
Hi Richie,
Thanks for your reply :-)
I have tried to find the Outlook Exp library in project - reference, but couldn't find it. I can only find Micr. Outlook 9.0.
Do you think I have to install a new library for Outlook Express ? How to install ?

Rgds.
Kiky

0
 
LVL 1

Expert Comment

by:wongchun
Comment Utility
Hi Kiky,

Can you find "Microsoft CDO 1.21 Library"? Please add this reference, then you can use CDO to save attachments.

Example Code:
    Dim objSession As MAPI.Session
    Dim objFolder As MAPI.Folder
    Dim objMessageList As MAPI.Messages
    Dim objMessage As MAPI.Message
    Dim objAttachmentList As MAPI.Attachments
    Dim objAttachment As MAPI.Attachment
    Dim objFilter As MAPI.MessageFilter

    On Error GoTo CheckMailErr
   
    Set objSession = CreateObject("MAPI.Session")
    ' Logon to the Exchange Server using Internet Mail method and profile
    objSession.Logon olProfile, olPwd
   
    Set objFolder = objSession.Inbox
    Set objMessageList = objFolder.Messages
    ' Set filter to get all unread mail
    Set objFilter = objMessageList.Filter
    objFilter.Unread = True
    Set objMessage = objMessageList.GetFirst
   
    If objMessage Is Nothing Then
    Else
      ' Loop until all mail are read
      Do While Not objMessage Is Nothing
                   
            Dim RndVal As String
            Dim AttPath As String
           
            ' Get a random number
            RndVal = CStr(CLng((Rnd * 99999999) + 1))
           
            ' Check folder name is exist
            While fso.FolderExists(locFolder + RndVal) = True
                ' Find a new random folder name
                RndVal = CStr(CLng((Rnd * 99999999) + 1))
            Wend
           
            fso.CreateFolder locFolder + RndVal
            AttPath = locFolder + RndVal
           
            ' Save attachments into a new and random folder
            ' *************************************************************************************
            Dim AttachmentIdx As Integer
           
            Set objAttachmentList = objMessage.Attachments
           
            For AttachmentIdx = 1 To objAttachmentList.Count
                Dim intLenFileName As Integer
                Dim intStrPos As Integer
                Dim strNewFileName As String
       
                Set objAttachment = objAttachmentList.Item(AttachmentIdx)
                strNewFileName = objAttachment.Fields(CdoPR_ATTACH_LONG_FILENAME)
                ' Save the attachment
                objAttachment.WriteToFile (AttPath & BACKSPLASH & strNewFileName)
       
            Next AttachmentIdx
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Thta library is installed with IE if you have told to instalkler to do so.
It is locayed in program files\outlook express folder.
0
 

Expert Comment

by:Huzaifa
Comment Utility
MAPI is your best bet for writing such programs , since u are a beginner please see the following link to learn more about MAPI controls
http://visualbasic.about.com/compute/visualbasic/library/weekly/aa051401a.htm

bye,
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
Huzaifa, that is just a general link, it doesn't really answer his question and thus should not have been posted as an answer.  As you are new here, please see this link for details on questions, comments and answers.  Also note that here in the VB forum we pretty much tend to use comments only, unless a) the question is trivial and no further information is needed and you are 110% sure it will answer the user's needs  and b) no-one else has made any valid suggestions.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
Oh yeah, it would help if I put the link:

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
By the way kiky, I don't think what you want can be done in Outlook Express.  OE is a Simple MAPI client, and that does not allow for much functionality.  Outlook Express does not expose a useful object hierarchy like Outlook does, so I'm guessing you're out of luck on this one.
0
 

Author Comment

by:kiky
Comment Utility
Hi Huzaifa,
Actually, I have tried to send/receive e-mail using MAPI through Outlook Exp. Everything's fine, but when I tried to do something else (read the subject, count messages in my inbox, etc), the MAPI always point back to Micr. Outlook.
I'm sorry I have to reject your answer to open the 'lock' :-)
Anyway, I do appreciate your help.

Rgds,
Kiky

0
 

Author Comment

by:kiky
Comment Utility
Hi PaulHews,
Thanks for your reply :-)
Do you think what I want really can't be done in Outlook Exp ? :-(
I thought MAPI was a low level message provider, and both of Micr Outlook or Outlook Express points to MAPI, so I could access any of them from MAPI.

Rgds,
Kiky






0
 

Author Comment

by:kiky
Comment Utility
Hi wongchun,
I have tried to copy-paste your code to my VB program, and I have put :
- Micr CDO for Wind 2K Lib and Micr CDO for NTS 1.2 Lib in my project-reference;
- MAPISession and MAPIMessages in my form
but I still get several compile errors on the variable declarations :
   Dim objSession As MAPISession
   Dim objFolder As MAPI.Folder (*error)
   Dim objMessageList As MAPIMessages
   Dim objMessage As MAPI.Message (*error)
   Dim objAttachmentList As MAPI.Attachments (*error)
   Dim objAttachment As MAPI.Attachment (*error)
   Dim objFilter As MAPI.MessageFilter (*error)

Is there anything that I miss, cause these errors ?

Anyway, thank you very much for your help :-)

Rgds,
Kiky

0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
>Do you think what I want really can't be done in Outlook Exp ? :-(

I don't think it can be done, but I've been wrong before.


>I thought MAPI was a low level message provider, and both of Micr Outlook or Outlook Express points
to MAPI, so I could access any of them from MAPI.

Yes, but while Outlook has full MAPI support, OE supports Simple MAPI which is a subset of MAPI.  This is why I think it won't work, as SMAPI is very limited.
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
INFO: Developer Support Limitations with Outlook Express
http://support.microsoft.com/support/kb/articles/Q239/5/76.ASP

INFO: Differences Between CDO, Simple MAPI, and Extended MAPI
http://support.microsoft.com/support/kb/articles/Q200/0/18.ASP
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
Comment Utility
Well, I feel dumb for repeatedly saying it couldn't be done, because here is the source code.  Some of it is from MSDN, and some of it I had to work out on my own.  You need to add the MapiSession and MapiMessages control to your form:

Option Explicit

Private Sub Command1_Click()
    Dim strNewFileName As String
    Dim i As Integer
    Dim j As Integer
    Dim intStrPos As Long
    Dim intLenFileName As Integer
   
    MAPISession1.SignOn 'session_signon
    MAPIMessages1.SessionID = MAPISession1.SessionID
   
    MAPIMessages1.Fetch 'message_fetch
   
    If MAPIMessages1.MsgCount > 1 Then
        For j = 0 To MAPIMessages1.MsgCount - 1
            MAPIMessages1.MsgIndex = j
            Debug.Print MAPIMessages1.MsgSubject
            If MAPIMessages1.MsgSubject = "My Subject" Then
                MAPIMessages1.Copy  'If I don't copy into compose buffer, attachment count is always zero
                Debug.Print "# attach " & MAPIMessages1.AttachmentCount
                For i = 0 To MAPIMessages1.AttachmentCount - 1
                    MAPIMessages1.AttachmentIndex = i
                   
                   
                    intLenFileName = Len(MAPIMessages1.AttachmentPathName)
                    intStrPos = InStrRev(MAPIMessages1.AttachmentPathName, "\")
                    If intStrPos > 0 Then
                        strNewFileName = Right$(MAPIMessages1.AttachmentPathName, intLenFileName - intStrPos)
                    End If
                    FileCopy MAPIMessages1.AttachmentPathName, "c:\temp\" & strNewFileName
                Next i
            End If
        Next j
    End If
   
    MAPISession1.SignOff
   
   
End Sub
0
 

Author Comment

by:kiky
Comment Utility
Hi PaulHews,
Thank you very very much for the code. It works !! :-)
BTW, here in my computer, I have to uninstall the Micr Office (to uninstall Outlook) first, before your program can point to OE. Before I uninstalled the Outlook, actually I had set my default mail client to point to OE, but your program still pointed to Outlook and couldn't read what inside the OE inbox, so then I uninstalled the Outlook.

is it really necessary to uninstall the Outlook or is there any other way to set the program so it can still point to OE without uninstalling the Outlook ?

Once again, thank you very much for your help. I really appreciate it :-)

Rgds,
Kiky Tan







0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
OLEXP: Set Outlook Express as Your Default Simple MAPI Client
http://support.microsoft.com/support/kb/articles/Q178/0/77.ASP

If that didn't work, the only thing I can think of is that it needed a reboot.
0
 
LVL 1

Expert Comment

by:wongchun
Comment Utility
P.S. The MAPI Control cannot save long filename files.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This very simple solution applies to a narrow cross-section of the "needs to close" variety. In this case, the full message in Event Viewer was in applog, Event ID 1000: Faulting application iexplore.exe, version 8.0.6001.18702, faulting module …
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now