Jump to content

Open Outlook Email Attachment


Recommended Posts

Hey

I need to be able to open the file attachment in an email, but I cant figure out how to do it. Using the following code, I am able to count the number of attachments (in this case there is only 1 file) and then display the name of the attachment(s), but I cant open the attachment. I have removed allot of stuff not pertaining to the email attachment portion of my code, but bascially the below code loops through a mailbox and as long as there is an item in the inbox, it analyzes the email.

Can anyone help me?

$g_oOutlook = ObjCreate("Outlook.Application")
$oOutlook = ObjCreate("Redemption.RDOSession")
$ns = $g_oOutlook.GetNameSpace("MAPI")
$oOutlook.MAPIOBJECT = $ns.MAPIOBJECT

$oFolder = $oOutlook.getfolderfrompath("\\Mailbox - CAR/TN Reporting\Inbox")
$mInbox = $oFolder.Items
$Items = $mInbox.count
$StartCount = $Items

    $Items = $mInbox.count
    ;Msgbox(0,"TOTAL EMAILS: ", "Items in Inbox: " & $Items)

    For $Item = $Items to 1 step -1
        $EmailCategory = ""
        $CategoryFlag = ""
        
        $message = $mInbox.item($Item)
        $mSubject = $message.subject
        ;Msgbox(0,"Email Subject",$mSubject)

        $Number_of_Attachments = $message.Attachments.count
        ;MsgBox(0, "Autoit:", "The count of file attachments is: " & $Number_of_Attachments)

        ;Email Category Trigger #2 - REPORT_Audits
        If $CategoryFlag = 1 Then
            ;SKIP
        Else
            If StringInStr($mSubject, "Audit Res") >= 1 and $Number_of_Attachments >=1 Then
                    For $att in $message.Attachments
                      MsgBox(0, "Search result:", "The attachment file name is: " & $att.filename)
                      FileOpen($att, 0)
                    Next
                $EmailCategory = "REPORT_Audits"
                $CategoryFlag = 1
            Else
                $CategoryFlag = 0
            EndIf
        EndIf
    Next
Edited by hutteto
Link to comment
Share on other sites

Hutteto,

Please remember to bump posts once every 24 hours (minimum).

I believe your understanding of FileOpen is limited. FileOpen will open the file for either reading or writing. I believe you want to run it, so Run ($att) or ShellExecute ($att) should do the trick.

Cheers,

Brett

Link to comment
Share on other sites

There is a saveasfile method :

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.attachment.saveasfile.aspx

You can save the attachment and then Shellexecute it.

After you are finished you can close and delete it.

This is what outlook do in general - when you double click attachment it saves it in the temporary outlook directory and then

open it with the default program for that extension

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...