Skip to main content

[archive] Outlook Inbox Message Count

  • July 10, 2006
  • 3 replies
  • 0 views

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

3 replies

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

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

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