Highlighted
Absent Member.
Absent Member.
472 views

[archive] Outlook Inbox Message Count

[Migrated content. Thread originally posted on 07 July 2006]

Hi,

Trying to write a simple bit of code to get a count of the number of unread emails in Outlook. Have got this far:

77 olApp HANDLE OF Application.
77 olNs HANDLE OF Namespace.
77 olItem HANDLE OF ContactItem.
77 olAppt HANDLE OF AppointmentItem.
77 olMail HANDLE OF MailItem.
77 olAttach HANDLE OF Attachments.
77 olInbox HANDLE OF Items.

01 WS-COUNT PIC S9(9) COMP-5.

PROCEDURE DIVISION.

A-GET-INBOX SECTION.
AA-START.

*******************************************************************
With T*is
* .oOutlook = Create(OUTLOOK_CLSID)
*
* .oSpace = .oOutlook.GetNameSpace('Mapi')
*
* .oInbox = .oSpace.GetDefaultFolder(6)
*
* If .oInbox.Items.Count
* Wait Window 'No new messages.' Nowait
* Return
* Endif
* .oMsg = .oInbox.Items(.oInbox.Items.Count)
* For Each .oMsg In .oInbox.Items
*
* lcSenderName = .oMsg.SenderName,;
* lcSubject = .oMsg.subject
* lcHTMLBody = .oMsg.HTMLbody
* lcTextBody = .oMsg.body,;
* lcEntryId = .oMsg.EntryId
* ltReceived = .oMsg.ReceivedTime,;
* ltSentOn = .oMsg.SentOn
*
* * place code here to save data in a table
* Next
Endwit*
**********************************************************************
display standard window
SH3125 title "Inbox"
user-colors
background-low
auto-minimize
auto-resize.

*Open the Outlook object (hooking into, if already running)
CREATE Application OF Outlook
HANDLE IN olApp.

MODIFY olApp GetNameSpace("MAPI")
GIVING olNs.

MODIFY olNs Logon().

MODIFY olNs GetDefaultFolder(6)
GIVING olInbox.

INQUIRE olInbox count IN WS-COUNT.

DISPLAY WS-COUNT.

DESTROY olNs.
DESTROY olApp.

AA-EXIT.
EXIT.

I have included within the cobol the code I am trying to translate into cobol.

This compiles but doesn't work.

Any help would be greatly appreciated.
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Outlook Inbox Message Count

You don't say WHAT fails. Please do this for the future, helps to find the solution.
However, I assume that what you get in the count, is the number of items in the inbox, read and unread alike.
What you need to do, is to set a filter, you can do this by;

MODIFY oInbox Items::Restrict("[Unread] = true")
giving oUnreadItems.
INQUIRE oUnreadItems Count IN nNumberOfUnreads.

Where
77 oUnreadItems HANDLE OF ITEMS.
77 nNumberOfUnreads PIC S9(9).

Also, oInbox is not a Items class, it is a MAPIFolder class.

Think this should do.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Outlook Inbox Message Count

Thanks, that has done the trick. And I'll be sure to give a better explanation next time.

This is just the first step in a project, but this will get me moving in the right direction.

Thanks again.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.