• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

Save Attachments From the Outlook Express Inbox to a File

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
kiky
Asked:
kiky
  • 8
  • 7
  • 3
  • +2
1 Solution
 
wongchunCommented:
I think you can try CDO or MAPI to do this.

Daniel
0
 
kikyAuthor Commented:
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
 
kikyAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kikyAuthor Commented:
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
 
Richie_SimonettiIT OperationsCommented:
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
 
kikyAuthor Commented:
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
 
wongchunCommented:
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
 
Richie_SimonettiIT OperationsCommented:
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
 
HuzaifaCommented:
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
 
PaulHewsCommented:
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
 
PaulHewsCommented:
Oh yeah, it would help if I put the link:

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
0
 
PaulHewsCommented:
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
 
kikyAuthor Commented:
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
 
kikyAuthor Commented:
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
 
kikyAuthor Commented:
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
 
PaulHewsCommented:
>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
 
PaulHewsCommented:
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
 
PaulHewsCommented:
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
 
kikyAuthor Commented:
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
 
PaulHewsCommented:
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
 
wongchunCommented:
P.S. The MAPI Control cannot save long filename files.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 8
  • 7
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now