Consulting

Results 1 to 6 of 6

Thread: Extract the outlook attachment and sender information

  1. #1
    VBAX Regular
    Joined
    Aug 2008
    Posts
    8
    Location

    Extract the outlook attachment and sender information

    Hello,

    Please is it possible to download the email attachment and the attachment's sender email address with VBA?
    My aim is to download the attachment as well as extracting the email address of the attachment's sender.

    Thanks

  2. #2
    Something like this should work for you:

    [VBA]Private Function SaveAttachmentsAndReturnSender(TheMsg As Object, DestinationFolder As String) As String
    If TheMsg Is Nothing Or DestinationFolder = "" Then Exit Function
    If Not TypeOf TheMsg Is Outlook.MailItem Or Not TypeOf TheMsg Is Outlook.MeetingItem Then Exit Function
    If TheMsg.Attachments.Count <= 0 Then Exit Function
    Dim CheckAttach As Outlook.Attachment
    For Each CheckAttach In TheMsg.Attachments
    CheckAttach.SaveAsFile DestinationFolder & "\" & CheckAttach.DisplayName
    Next CheckAttach
    SaveAttachmentsAndReturnSender = TheMsg.SenderEmailAddress
    'SaveAttachmentsAndReturnSender = TheMsg.SenderName
    End Function[/VBA]

  3. #3
    VBAX Regular
    Joined
    Aug 2008
    Posts
    8
    Location
    Hello jfournier,
    Thanks very much for your reply. I had tried the above procedure and I am having some difficulties to make it to work. It seems the issue is with the declaration or the references that I have setup. Do you have the declaration portion prior to calling the function?
    Thanks,

  4. #4
    What do you mean by the declaration? Do you mean getting a reference to the mailitem you want to extract the attachments and sender info from?

  5. #5
    VBAX Regular
    Joined
    Aug 2008
    Posts
    8
    Location
    Hi,

    Yes, It seems my reference is not working correctly,which I am running from Access database(VBA) and it prevents the process from saving the outlook attachments to C drive, as well as extracting the email id of the sender. Also is it possible to use the procedure to move the emails with attachments to an Inbox folder as well.

    Thanks,

  6. #6
    I'm not sure but it sounds like it may be a security setting messing with saving your attachments and extracting sender email address. I know I've had issues accessing a mailitem's body and sender information from outside of Outlook VBA, I didn't know if it was an issue with VBA in Access or the rest of Office. But my guess is it's a security issue, which is pretty hard to overcome without resorting to commercial tools like this one:
    http://www.add-in-express.com/outlook-security/

Posting Permissions

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