Sign in to follow this  
Followers 0
eagle51

Outlook (Move an Email)

2 posts in this topic

Hallo together,

what I want to do:

move a specific E-Mail from the outlook default folder to another. e.g. "folder_new".

My problem is the move-command for the email.

What I found was $Message.Copy. But I don't know how to use this :P

$oOutlook = ObjCreate("Outlook.Application")
$oMAPI = $oOutlook.GetNameSpace ("MAPI") 
$InboxItems = $oMAPI.GetDefaultFolder ($oOutlookFolderInBox).Items ;Read all mails from inbox

For $Pos = $InboxItems.Count To 1 Step - 1 
$Message = $InboxItems.Item ($Pos) 

; If sender = ......... 
; HERE THE MOVE-MAIL COMMAND
 ...

Thanks in advance :)

e51

Share this post


Link to post
Share on other sites



You made me finally break down and study the Outlook Object Model. It's not as easy as IE, Word, or Excel, but after a while you get the hang of it.

Here is an example that I tested on my Outlook Profile, hopefully it works well for you.

#include <IE.au3>

Global Const $olFolderInbox = 6

$sSender = "someone@somewhere.com"
$sNewFolder = "Test Folder"

_IEErrorHandlerRegister()
$o_Outlook = ObjCreate("Outlook.Application")
$oNameSpace = $o_Outlook.GetNameSpace("MAPI")
$oInbox = $oNameSpace.GetDefaultFolder($olFolderInbox)
$oFolders = $oInbox.Parent.Folders

$oNewFolder = 0
For $oFolder In $oFolders
    If String($oFolder.Name) = $sNewFolder Then
        $oNewFolder = $oFolder
    EndIf
Next

If Not IsObj($oNewFolder) Then
    $iReturn = MsgBox(4, "Warning", "Folder '" & $sNewFolder & "' was not found." & @CR & @CR & _
            "Would you like to create it?")
    If $iReturn = 6 Then
        $oNewFolder = $oFolders.Add($sNewFolder)
        If Not IsObj($oNewFolder) Then
            MsgBox(64, "Error", "Unable to create the folder '" & $sNewFolder & "'.")
            Exit
        EndIf
    Else
        Exit
    EndIf
EndIf

$oItems = $oInbox.Items
For $oItem In $oItems
    If String($oItem.SenderEmailAddress) = $sSender Then
        $oItem.Move($oNewFolder)
    EndIf
Next

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  
Followers 0