Results 1 to 5 of 5

Thread: MAPI E-mail Accessing File Attchments from e-mail

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    UK
    Posts
    2

    Question

    How can I save an Attchment from an e-mail that has been retreived using MAPISession & MAPIMessages objects from within VB. How can I Access the attachment. I just want to save it to a folder on my hard disk. Any help would be appreciated.

    Regards

    Eric Hart.

  2. #2
    New Member
    Join Date
    May 2000
    Posts
    11

    ??? i dunno

    Check the APItext viewer, maybee it has an api call...
    "Beyond the pretty wrapping paper, all life is, is just a struggle between one hard spot and the next, puncuated by a failure of biological systems."- Codewarrior123

  3. #3
    Member
    Join Date
    Nov 2000
    Location
    Vienna, Austria
    Posts
    62

    Wink

    Here is a way to access the mail in gerneral. If you want to access the attachment you will have to access objMail.attachments and maybe(I am not sure) the commant to save the attachment would be objMail.attachments.save
    Good luck!
    --------------------------------------------
    Sub ReadFolder()

    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objMail As Outlook.MailItem
    Dim intItemCount As Integer

    'create objects, get mapi
    Set objOL = New Outlook.Application
    Set objNS = objOL.GetNamespace("MAPI")

    'get inbox
    Set objFolder = objNS.GetDefaultFolder(olFolderInbox)

    'loop thru inbox, display items
    For intItemCount = 1 To objFolder.Items.Count
    Set objMail = objFolder.Items.Item(intItemCount)
    Debug.Print objMail.SenderName & ": " & objMail.Subject
    Next intItemCount

    'cleanup
    Set objFolder = Nothing
    Set objMail = Nothing
    Set objNS = Nothing
    Set objOL = Nothing

    End Sub
    -----------------------------------------------------
    Life is trip, eat it and smile.

  4. #4
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Smile Attachments collection

    Each MAPI message has an Attachments collection. Each Attachment object has a WriteToFile method, so it becomes quite easy.

    Code:
      Dim AttachmentItem as MAPI.Attachment
      
      For Each AttachmentItem In vMessage.Attachments
        If AttachmentItem.Type = CdoFileData Then
          strFilePath = TempPath & AttachmentItem.Name
          Call AttachmentItem.WriteToFile(strFilePath)
        End If
      Next AttachmentItem
    Hope this helps.
    Shrog

  5. #5
    Addicted Member Nice's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    144
    thatz a gud soln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width