none
How to access unread mails of all users in Exchange server without having Passwords and without giving mailbox access to other user RRS feed

  • Question

  • Hi all,

       I am using Exchange server 2013, my task is to create Service , that need's to  monitor continuously for new mails of all Mailboxes in my server. if any user got new mail i need to get that Mail Subject, Mail Body, Sender Email Address [From emailId] .  

    Limitation : I don't have Passwords of mailboxes , so i gave all mailbox access permission  to one user , then i completed this   service using below code.

     But now, Client not willing to give Mailbox Permissions to one user because of security problems.

    How can i do this without passwords and without giving permissions to other user ?

    i don't want all mailbox access , i just need only access Mail Subject , Body and Sender mail address .

    How can i achieve this ?


    Process i follow

    => I created new user in server , and then i gave full permissions of all Mailboxes to newly created user[ex: james] in database level.

         i use below command for giving permissions in database level.

    Get-MailboxDatabase -Identity <Database Name> | Add-ADPermission -User <User> -AccessRights GenericAll

     => using below code i am searching unread mails of all user Mailboxes and then getting Subject, body and Sender Email            address . here i am have list of users,

    ExchangeService service = new   ExchangeService(ExchangeVersion.Exchange2013);
                    service.Credentials = new WebCredentials("james@admin.com", "password");
                    service.AutodiscoverUrl("james@admin.com");          
                foreach (Object obj in usersList) // here i have Mailbox users list in usersList 
                 {
                  var userMailbox = new Mailbox(obj.user); 
                  var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);
            SearchFilter.IsEqualTo filter1 = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);
    
                     var itemView = new ItemView(50);
                    var userItems = service.FindItems(folderId, filter1, itemView);
    
                             foreach (var item in userItems)
                             {
                                 item.Load();
                                 var senderEmail = ((EmailMessage)item).From;
                                 var subject = item.Subject;
                                 var body = item.Body;
                             }
                 }

    Tuesday, July 1, 2014 5:08 AM

Answers