seadoggie01 Posted September 24, 2019 Share Posted September 24, 2019 (edited) 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 September 24, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted October 1, 2019 Moderators Share Posted October 1, 2019 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 More sharing options...
seadoggie01 Posted October 1, 2019 Author Share Posted October 1, 2019 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 functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now