Retrieve mail & attachments (programmatically)

Posted on 2003-02-28
Medium Priority
Last Modified: 2010-05-01
Each day I’m (now) being sent an email with a data file as an attachment. I’d like to get the attached file, parse it, and write it to Access. The part that I can’t figure out yet is how to retrieve the email and the attached file using a script. Does anyone know of an object I can set that’ll do this?

Thanks in advance
Colin West
Question by:cwest1
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

Accepted Solution

DocM earned 150 total points
ID: 8045547
Here is one way to do it with the MAPISession and the MAPIMessages components from Microsoft MAPI Controls.

Private Sub Save_EMail()
   Dim MIndex As Integer
   If MAPISession1.SessionID = 0 Then MAPISession1.SignOn
   With MAPIMessages1
       .SessionID = MAPISession1.SessionID
       .FetchSorted = True
       .FetchUnreadOnly = True
       For MIndex = 0 To .MsgCount - 1
           If .MsgOrigAddress = "<Sender's email address>" Then
               MsgAttachmentName = .AttachmentName
               If MsgAttachmentName <> "" Then
               Open MsgAttachmentName For Input As #3
                While EOF(3) = False
                 AttachedFileContent = Input(FileLen(MsgAttachmentName), 3)
                 'Do what you want with AttachedFileContent
               Close #3
               End If
        End If
       Next MIndex
   End With
   Close #1
End Sub

Expert Comment

ID: 8940425
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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