MS Outlook Module - Get only unread email & Set email as Read

Hi, I'm using MS Outlook Module to get a email list and then working on them, I have already implemented these steps. Now I would get email list but only unread email, then I need to mark the emails in this list as read. What is the best way to do it?

Thank you!

  Discussion posts and replies are publicly visible

Parents
  • It is not possible get an email list with only unread emails. The behavior of the MSOutlook module is the same as you can get using the GUI. When you access to a folder, you see by default all the emails.

    The IOlMailItem object contains a property to know whether the email has been read. You can use mailItem.getUnread() method.

    To mark an email as read, you can do the same thing as in the GUI, show the email, and close it. 

    Here you are an example:

    			IOlFolderFW criteria = new OlFolderFW();
    			criteria.setFolderPath("\\\\myAccount@myCompany.com\\Inbox");
    			List<IOlFolder> folderList = outlook.getOlFolderManager().findFolder(criteria);
    			         
    			List<IOlMailItem> mailList = outlook.getOlFolderManager().getMailList(folderList.get(0).getEntryID());
    			         
    			for (IOlMailItem mailItem : mailList) {
    				if (mailItem.getUnRead()) {
    					server.info("Mail Unread, Subject <"+mailItem.getSubject()+">, Sender <"+mailItem.getSenderName()+">");
    					outlook.getOlMailManager().showMail(mailItem);
    					//Do Something....
    					outlook.getOlMailManager().closeMail(mailItem.getEntryID(), EInspectorClose.DISCARD);
    				}
    			}
    

    To manage this type of automation I recommend you don't use the unread property to decide whether an email must be processed or not. I think it is better process all emails in the input folder. When an email is processed, the robot can move the email to another folder ( called "processed" for example), to not be processed twice..

Reply
  • It is not possible get an email list with only unread emails. The behavior of the MSOutlook module is the same as you can get using the GUI. When you access to a folder, you see by default all the emails.

    The IOlMailItem object contains a property to know whether the email has been read. You can use mailItem.getUnread() method.

    To mark an email as read, you can do the same thing as in the GUI, show the email, and close it. 

    Here you are an example:

    			IOlFolderFW criteria = new OlFolderFW();
    			criteria.setFolderPath("\\\\myAccount@myCompany.com\\Inbox");
    			List<IOlFolder> folderList = outlook.getOlFolderManager().findFolder(criteria);
    			         
    			List<IOlMailItem> mailList = outlook.getOlFolderManager().getMailList(folderList.get(0).getEntryID());
    			         
    			for (IOlMailItem mailItem : mailList) {
    				if (mailItem.getUnRead()) {
    					server.info("Mail Unread, Subject <"+mailItem.getSubject()+">, Sender <"+mailItem.getSenderName()+">");
    					outlook.getOlMailManager().showMail(mailItem);
    					//Do Something....
    					outlook.getOlMailManager().closeMail(mailItem.getEntryID(), EInspectorClose.DISCARD);
    				}
    			}
    

    To manage this type of automation I recommend you don't use the unread property to decide whether an email must be processed or not. I think it is better process all emails in the input folder. When an email is processed, the robot can move the email to another folder ( called "processed" for example), to not be processed twice..

Children
No Data