none
Check sender mail address exists with in the Contacts list 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 and check sender mail address exists with in the Contacts list of my mail box or not.

    what is the best way to monitor mail box continuously ? , i need to give this service to PHP team to consume it in their Application.

    kindly help with some information or sample code .

    Wednesday, March 26, 2014 6:58 AM

Answers

  • Your service is ok.

    For control inbox of more emails u can do something like this:
    -Create a list and put emails to monitor in it
    -Check for each one the inbox mails not read yet
    -Take informations
    -Update it.

    using System.Thread;  
    public static void Main (String[]args){
    
    List<sting> emails = new List <sring>();
    emails.Add("email1@domain.com");
    emails.Add("email2@domain.com");
    
       ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Credentials = new WebCredentials("david@admin.com", "admin2014!@");
                service.AutodiscoverUrl("david@admin.com", RedirectionUrlValidationCallback);
    //if ur service have to monitor 24/7 the inbox mail
    while(true)
    {
       for(int i = 0 ; i < emails.Count ; i++)
       {
         //U must be delegate on their mailbox
         Folder inboxFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, email));
        FindItemsResults<Item> findResults = inboxFolder.FindItems(searchFilter, view);
          foreach (Item item in findResults.Items)
                 {
                     //item.Load();
    
                     var senderEmail = ((EmailMessage)item).From;  // ((EmailMessage)item).Sender;
    
                     ((EmailMessage)item).IsRead = true;
    
                      item.Update(ConflictResolutionMode.AlwaysOverwrite);
                   
                 }
    
       }
    /*
    When all emails are checked it sleeps for 5 mins before redo the job
    */ 
    Thread.Sleep(300000);
    }
       
    }
    
    
               

    This is the first solution that came to my mind and I didn't test it.

    Hope that it can be useful in some way for u :)

    Stefano


    • Marked as answer by Dora407 Thursday, May 8, 2014 1:20 PM
    Monday, April 7, 2014 1:55 PM

All replies

  • Do you only need to do this on one mailbox ? or for every mailbox in an Organization.

    If its only one (or just a few mailboxes) the EWS notifications are something you can use so you get notified when a new message arrives see http://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx 

    If you need to do this for every mailbox in a Org then you could look at using Transport Agent. What a Transport Agent would give you the ability to do is process the message while its in the Transport PipleLine before it hit the mailboxes see http://msdn.microsoft.com/en-us/library/office/bb204097(v=exchg.150).aspx

    The other method you could use is just to use the Message Tracking logs, this will list the Sender and recipient address of messages are being sent and received http://technet.microsoft.com/en-us/library/bb124375(v=exchg.150).aspx . This removes the need to watch the inbox if that is the only piece of information your after and maybe a simpler method.

    Cheers
    Glen

    Thursday, March 27, 2014 1:28 AM
  • Hi Glen,

    Thanks for reply,

    Maximum 10 user members exists in their Application [PHP Application]. same users  exists in Exchange server.

    i need to create service that, if any user [ex: David] got new mail , i need to check  Sender  Email address Exists with in David Contacts or  not.

    if Mail address is exists in David Contact i need to create one Activity in their Application[ that's secondary].

    At present i am creating service that,   to get unread mails of one user , through that i find sender Email Address and then i need to search sender Email Address Exists in that User Contacts or not.


    Code:

      

      ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Credentials = new WebCredentials("david@admin.com", "admin2014!@");
                service.AutodiscoverUrl("david@admin.com", RedirectionUrlValidationCallback);
    
                int unreadEmailCount = 0;
    
                SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
    
                ItemView view = new ItemView(50);
    
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
    
                unreadEmailCount = findResults.Items.Count;
    
               
                 foreach (Item item in findResults.Items)
                 {
                     //item.Load();
    
                     var senderEmail = ((EmailMessage)item).From;  // ((EmailMessage)item).Sender;
    
                     ((EmailMessage)item).IsRead = true;
    
                      item.Update(ConflictResolutionMode.AlwaysOverwrite);
                   
                 }
              

    i think this service is good for one user only, they can call this service for Every 5 minutes. but 10 members exists in their application, they need to monitor all user mailboxes in their application

      i am going in right way ? , Please suggest me



    • Edited by Dora407 Thursday, March 27, 2014 1:29 PM
    Thursday, March 27, 2014 1:22 PM
  • Your service is ok.

    For control inbox of more emails u can do something like this:
    -Create a list and put emails to monitor in it
    -Check for each one the inbox mails not read yet
    -Take informations
    -Update it.

    using System.Thread;  
    public static void Main (String[]args){
    
    List<sting> emails = new List <sring>();
    emails.Add("email1@domain.com");
    emails.Add("email2@domain.com");
    
       ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Credentials = new WebCredentials("david@admin.com", "admin2014!@");
                service.AutodiscoverUrl("david@admin.com", RedirectionUrlValidationCallback);
    //if ur service have to monitor 24/7 the inbox mail
    while(true)
    {
       for(int i = 0 ; i < emails.Count ; i++)
       {
         //U must be delegate on their mailbox
         Folder inboxFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, email));
        FindItemsResults<Item> findResults = inboxFolder.FindItems(searchFilter, view);
          foreach (Item item in findResults.Items)
                 {
                     //item.Load();
    
                     var senderEmail = ((EmailMessage)item).From;  // ((EmailMessage)item).Sender;
    
                     ((EmailMessage)item).IsRead = true;
    
                      item.Update(ConflictResolutionMode.AlwaysOverwrite);
                   
                 }
    
       }
    /*
    When all emails are checked it sleeps for 5 mins before redo the job
    */ 
    Thread.Sleep(300000);
    }
       
    }
    
    
               

    This is the first solution that came to my mind and I didn't test it.

    Hope that it can be useful in some way for u :)

    Stefano


    • Marked as answer by Dora407 Thursday, May 8, 2014 1:20 PM
    Monday, April 7, 2014 1:55 PM