Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reading e-mail attachments

Posted on 1999-10-03
10
Medium Priority
?
211 Views
Last Modified: 2010-05-02
how can I automatically open e-mail attachments in msexchange,one by one, that are in text form and insert the contents in a textbox where I can read the contents using MAPI? If you can answer this by October 6,1999(today's 10/4/1999) i'll be willing to part with you 300pts
0
Comment
Question by:meng_97
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 

Author Comment

by:meng_97
ID: 2095387
Edited text of question.
0
 
LVL 3

Accepted Solution

by:
troywillmot earned 800 total points
ID: 2095473
Microsoft have a DLL called olemsg.dll, a search for it or Microsoft Active Messaging on the Microsoft site should find it.

It has a whole bunch of classes in it for creating/reading emails and their attachements, as well as navigating MAPI email 'folders' etc.

It comes with a help file, so have a look at that.
0
 
LVL 3

Expert Comment

by:troywillmot
ID: 2095508
Hi, to be more specific, the following code uses the DLL I mentioned before to go through all the messages in the current users inbox and put the contents of the first attachement from each one into a text box called text1 on a form called form1.

You can modify it/clean it up to do what you want.

  Dim EMailMessage As Message
  Dim EMailSession As session
  Dim EMailRecipient As Recipient
  Dim EMailAttachment As Attachment
  Dim EMailFolder As Folder
  Dim SubFolder As Folder
  Dim Attachement As Attachment
 
  Dim Content As String
  Dim Cnt As Long
 
  ' create a session then log on, supplying username and password
  Set EMailSession = CreateObject("MAPI.Session")
  ' change the parameters to valid values for your configuration
  EMailSession.Logon

  Set EMailFolder = EMailSession.InfoStores("Personal Folders").RootFolder
 
  For Cnt = 1 To EMailFolder.Folders.Count
    If EMailFolder.Folders(Cnt).Name = "Inbox" Then
      Set SubFolder = EMailFolder.Folders(Cnt)
      Exit For
    End If
  Next Cnt
 
  For Cnt = 1 To SubFolder.Messages.Count
    Set EMailMessage = SubFolder.Messages(Cnt)
    If EMailMessage.Attachments.Count > 0 Then
      Set Attachement = EMailMessage.Attachments(1)
     
      Attachement.WriteToFile "c:\temp\tmp1.atc"
     
      Open "c:\temp\tmp1.atc" For Binary Shared As #1
        Content = Space$(LOF(1))
        Get #1, 1, Content
      Close #1
     
      Kill "c:\temp\tmp1.atc"
     
      Form1.Text1 = Form1.Text1 & Content
    End If
  Next Cnt
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:meng_97
ID: 2095714
Hi Thanks very much for such a quick response, but could u please explain the codes? I mean just put comments on what it does I'm not good at reading codes, I'm more of concepts and ideas, nad is not very good at coding. And if your kind enough, could you please write some other codes in other ways? jut incase this one won;t work for me :) THANKS!!
0
 

Author Comment

by:meng_97
ID: 2095742
Hi Thanks very much for such a quick response, but could u please explain the codes? I mean just put comments on what it does I'm not good at reading codes, I'm more of concepts and ideas, nad is not very good at coding. And if your kind enough, could you please write some other codes in other ways? jut incase this one won;t work for me :) THANKS!!

I tried the Codes bu the declarations didn't work!
0
 

Author Comment

by:meng_97
ID: 2096140
Edited text of question.
0
 
LVL 3

Expert Comment

by:troywillmot
ID: 2098045
Sure. Sorry, I should have done that in the first place. The code wasn't very neat to begin with, so its no wonder you had trouble. Let me know if this is any better.


  'Declare some object variable's we're going to need -
  ' we must reference the Microsoft Active Messaging DLL
  ' before this will work

  Dim EMailMessage As Message    
  Dim EMailSession As session        
  Dim EMailAttachment As Attachment
  Dim EMailFolder As Folder
  Dim SubFolder As Folder  
  Dim Attachement As Attachment
 
  'Declare a couple of primitive variables for holding
  'strings/doing loops
  Dim Content As String
  Dim Cnt As Long
   
  ' create a session then log on, supplying username and
  'password, or in our case just logon without (I Believe
  ' that lets us in under the current user)
 
  Set EMailSession = CreateObject("MAPI.Session")

  ' change the parameters to valid values for your
  'configuration - i.e, pass a user name and password if
  'required
  EMailSession.Logon

  'Get the root EMail folder - in my case I use outlook
  'for  my MAPI client so its 'Personal Folders' - outlook
  'express etc may use a different folder name, so it might
  'be better just to use numeric indexes and select the
  'first one, i.e
  'Set EMailFolder = EMailSession.InfoStores(1).RootFolder
  'But for this example, I'll just use "Personal Folders"

  Set EMailFolder = EMailSession.InfoStores("Personal Folders").RootFolder

  'For each sub folder in the root folder, check its name
  'until we find the inbox
  For Cnt = 1 To EMailFolder.Folders.Count
    If EMailFolder.Folders(Cnt).Name = "Inbox" Then
      'We found the inbox so set out subfolder variable
      'and exit the loop
      Set SubFolder = EMailFolder.Folders(Cnt)
      Exit For
    End If
  Next Cnt
   
  'Subfolder should now contain the object that is the
  'inbox, but in a real system you'd check to see if sub
  'folder was nothing before trying to use it

  'Now, for each message in the inbox (subfolder)
  For Cnt = 1 To SubFolder.Messages.Count
    Set EMailMessage = SubFolder.Messages(Cnt)
    'Check to see if the message has an attachement
    If EMailMessage.Attachments.Count > 0 Then
      ' Get the first attachement - note, in your case
      'you may want to loop here from 1 to
      'emailmessage.attachements.count
      Set Attachement = EMailMessage.Attachments(1)
     
      'Save the contents of the attachment to a file (the
      'only way I know of to read it)
      Attachement.WriteToFile "c:\temp\tmp1.atc"
     
      'Open the file we saved
      Open "c:\temp\tmp1.atc" For Binary Shared As #1
      'Read the files contents
        Content = Space$(LOF(1))
        Get #1, 1, Content
      Close #1
       
      'Kill the file
      Kill "c:\temp\tmp1.atc"
       
      'Put the contents of the attachment into the text box
      Form1.Text1 = Form1.Text1 & Content
     
      'Clean up our content variable
      Content=vbnullstring
    End If
  Next Cnt
0
 
LVL 3

Expert Comment

by:troywillmot
ID: 2098540
You can download the required DLL's from :

http://msdn.microsoft.com/vbasic/downloads/addon.asp
0
 
LVL 3

Expert Comment

by:troywillmot
ID: 2098542
The declarations didn't work ?

Did you include a reference to the DLL I said you needed ?
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6859129
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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