Jump to content

Outlook: Convert Message to Post Item


 Share

Recommended Posts

Hello,

I'm trying to copy an item to one of the public folders at my workplace. I'm using water's OutlookEx, but _OL_ItemCopy returns an error 3 because the Folder contains PostItems and not MailItems. I thought I would be able to save the mail item as a .msg file and use CreateItemFromTemplate($fullPath, $PublicFolder), but that created an MailItem from the message.

Basic code as follows:

#include <CustomDebugging.au3>
#include <OutlookEX.au3>

Global Const $olPublicFoldersAllPublicFolders = 18

main()

Func Main()

    Local $oOL = _OL_Open()
    If ErrMsg(@error, "OL Open") Then Exit
    Local $path = @DesktopDir & "\temp.msg"
    Debug("Path: " & $path)
    Local $sFolder = _OL_FolderAccess($oOL, "", $olPublicFoldersAllPublicFolders, Default)
    If ErrMsg(@error, "OL Folder Access") Then Exit
    Local $oFolder = _OL_FolderGet($oOL, $sFolder)
    If ErrMsg(@error, "OL Folder Get") Then Exit
    
    ; Custom error handler
    Local $oErrorHandle = ObjEvent("AutoIt.Error", "ErrHnd")

    Local $oNewObject = $oOL.CreateItemFromTemplate($path, $oFolder[1])
    If ErrMsg(@error, "CreateItemFromTempate") Then Exit

    Debug("Type: " & ObjName($oNewObject))

    $oNewObject.Save()
    If ErrMsg(@error, "Save") Then Exit
    
    $oNewObject.Post()
    If ErrMsg(@error, "Post") Then Exit
    
    $oErrorHandle = ""
EndFunc

It outputs that it is a MailItem and gives an error on .Post (the PostItem equivalent of MailItem.Send)

Does anyone know how to convert a MailItem into a PostItem? I know it has to be possible because I can drag and drop messages into the folder and they are imported 😐

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

  • Moderators

Try something like this...

#include <OutlookEX.au3>

Global Const $olPublicFoldersAllPublicFolders = 18

$sTemplatePath = @DesktopDir & "\temp.msg"

Main($sTemplatePath)

Func Main($sTemplatePath)
    Local $oErrorHandle = ObjEvent("AutoIt.Error", "ErrHnd")

    Local $oOutlook = _OL_Open()
    Local $aFolder = _OL_FolderAccess($oOutlook, "", $olPublicFoldersAllPublicFolders)
    Local $oFolder = _OL_FolderGet($oOutlook, $aFolder)
    $oItem = _OL_ItemCreate($oOutlook, $olPostItem, $oFolder, $sTemplatePath)
    $oItem.Post

    $oErrorHandle = ""
EndFunc

 

Link to comment
Share on other sites

Thanks, I actually found out it was a bit of an issue with the UDF... it has a check (in ItemCopy and ItemModify iirc) to ensure that items copied to the folder were of the same type, but the check wasn't necessary. After talking to water about this and removing the lines from a few functions, everything works fine with _OL_ItemCopy and the item was copied to the public folder. I'll try your code when I get back to work though, because that's an interesting solution :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

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...