nooneclose Posted April 4, 2019 Posted April 4, 2019 (edited) Hello everyone, I am wondering if and how it is possible to connect my AutoIt script to a different email in my outlook. I have two different accounts when I open outlook. The first which my script always connects to is my own email while the second is a group email account. How or can I make the script connect to the second one and access its inbox instead of mine? This is all work related so no funny business here. Global $oOutlook = _OL_Open() ; Store all the Unread emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "Maintenance Request from Eagle's Nest", "EntryID,Subject", "", 1) ; Display the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Get the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) ConsoleWrite("Number of unread emails: " & $numberOfUnRead & @CRLF) I might be missing some code in the post but my code works It's just so long I don't want to post all 2300+ lines. Thank you for the help I greatly appreciate this community. Edited April 8, 2019 by nooneclose
Nine Posted April 4, 2019 Posted April 4, 2019 Well I am using 2 different accounts registered in the same OutLook instance, and I get to see both accounts emails inside the same Inbox folder... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
nooneclose Posted April 4, 2019 Author Posted April 4, 2019 (edited) Thank you for getting back with me, but how do I tell my script to access the emails in the box named "Outlook-UDF-Test" under the second (email/group account)? Edited April 4, 2019 by nooneclose
Nine Posted April 4, 2019 Posted April 4, 2019 (edited) Here the code I use to see both accounts (2 different emails). The column To is one easy way to know which account is involved. #include <Constants.au3> #include "OutlookEX 1.3.4.1\OutlookEX.au3" Opt ("MustDeclareVars", 1) Global $oOutlook = _OL_Open(True,@ScriptDir & "\OutlookEX 1.3.4.1\_OL_Warnings.exe",10) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error) Global $aFolder = _OL_FolderAccess($oOutlook, "", $olFolderInbox) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing the default contacts folder. @error = " & @error) $aFolder[1].Display Global $aItems = _OL_ItemFind($oOutlook, $aFolder[1], $olMail, "", "", "", "EntryID,SenderEmailAddress,SenderName,Subject,To", "", 1) Global $oItem = _OL_ItemGet($oOutlook, $aItems[1][0], Default, -1) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing properties. @error = " & @error) $oItem.Unread = True If IsArray($aItems) Then _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind Example Script") Else MsgBox(48, "OutlookEX UDF", "Could not find an unread mail. @error = " & @error) EndIf _OL_Close($oOutlook) Win 7 - Outlook 2003. You must tell Outlook to put both accounts in same folder. Edited April 4, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
water Posted April 4, 2019 Posted April 4, 2019 Use _OL_Folderaccess to access a folder in another mailbox. The example script provided with the UDF explains how. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
nooneclose Posted April 5, 2019 Author Posted April 5, 2019 I still do not understand. I looked into the Outlook UDF and tried @Nine code but I can not figure it out. Here is an edited / "made up" picture of the folder I am trying to create / access in outlook. I am trying to create and access the "Outlook-UDF-Test" folder under the account "m" and put it in that account's inbox. I can create the "Outlook-UDF-Test" folder under the "a" account just fine. I do not get why putting it under "m" is not working. What am I not understanding?
nooneclose Posted April 8, 2019 Author Posted April 8, 2019 I found another solution that works. This may not be the best way but it works for me for now. Since I could not figure out how to make _OL_Open create the Outlook-UDF-Test folder under the account "M", because "M" is not the default, I changed my outlook account settings to make "M" the default E-mail and the default data files. My 2,400+ line email AI is able to work its magic again. Thank you very much for your time and effort @water and @Nine. If either of you have any more tips or code I could try I would love to make this process a 100% AutoIt script.
nooneclose Posted July 19, 2019 Author Posted July 19, 2019 (edited) I was able to use the code below to access the other email account (that I had permission and access to use. It was not a public account). Special thanks to @water for making this more clear to me. $aFolder = _OL_FolderAccess($oOutlook, "WorkEmail@hotmail.com", $olFolderInbox) ; This format is language independant I was also able to use this code (shown below) to double-check and see if it worked for what I was trying to do. (And it did ) Global $aItems = _OL_ItemFind($oOutlook, "*", $olMail, "[UnRead]=True", "Subject", "Work Request", "EntryID,Subject", "", 1) ; Display the array of unRead emails _ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ConsoleWrite("Number of unread emails: " & $numberOfUnRead & @CRLF) Edited July 19, 2019 by nooneclose
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