We help IT Professionals succeed at work.

Script to Get count of new mails in Outlook

480 Views
Last Modified: 2012-05-08
Hi,

I need to write a VB Script or VC++ program to get total number of new emails in outlook. Can anyone tell me or point me at suitable code/documentation?

Thanks in Advance,

Y
Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:

Author

Commented:
Thanks for info bp...

What does SERVERNAME and MAILBOXNAME stand for? is it the IP of server and mail client name?

cscript ProcessNotesEmails.vbs SERVERNAME MAILBOXNAME

Author

Commented:
+ one more thing,

I want to run this script on the client side. My mail server is hMailServer. Asif now, I am trying to write the script w.r.t. http://www.hmailserver.com/documentation/latest/?page=com_objects

Y

Author

Commented:
I was able to write/get code for getting unread mails in Inbox.

This attached script is limited only to get unread mails from Inbox - and not from Sub folders.

Can anyone help me to update this script to traverse through sub folders and get count of unread mails?

Any help is appreciated, Thanks in Advance.
' *****************************************************
'     Script To Display Unread Outlook Mail Items     *
'                                                     *
' ***************************************************** 

Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim CurrentItem
Dim Count 
Const olFolderInbox = 6 
    Set objOutlook = CreateObject("Outlook.application")
    Set objNameSpace = objOutlook.GetNameSpace("MAPI")
    Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox) 
    For Each CurrentItem in objFolder.Items
        If CurrentItem.Unread then
            Count = Count+1
        End If
    Next 
Msgbox("Unread Messages in Inbox:" &Count) 
 
' ****  Clean up
'
    Set objFolder = Nothing
    Set objNameSpace = Nothing
    set objOutlook = Nothing

Open in new window

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:

Author

Commented:
Hi bp, Again, thanks for your input.

Code which you are pointing at is VBA code and I need VBS script. Fact is - I dont know VBA and macros and many other things. I am newbie to all this coding work. I am managing somehow with VB Script in critical time.

I would appreciate if anyone helps me out for completing above script for traversing through sub folders and get count of unread mails?

Regards,
Y
error.jpg
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks alot bp for your kind help!! I really appreciate your help.

Yogi

Author

Commented:
Hi ,

is there any way to update this same script for getting sync complete notification?
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
You might take a look at this thread.  Your question is quite a bit different though than what this current question was about, just counting unread emails.  Trapping sync complete events is more complex.

https://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24897422.html

~bp
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.