Jump to content
Sign in to follow this  

Open Outlook Email Attachment

Recommended Posts



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")

$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
            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)
                $EmailCategory = "REPORT_Audits"
                $CategoryFlag = 1
                $CategoryFlag = 0
Edited by hutteto

Share this post

Link to post
Share on other sites


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.



Share this post

Link to post
Share on other sites

There is a saveasfile method :


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

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.