开发者

Programmatically monitor Exchange Inbox and print label

开发者 https://www.devze.com 2023-02-08 21:48 出处:网络
Here\'s what I have... I have a program that keeps track of barcode type labels. I can select an item in the database and print a label for it. I am adding the ability to send an email to a specific

Here's what I have...

I have a program that keeps track of barcode type labels. I can select an item in the database and print a label for it. I am adding the ability to send an email to a specific inbox on our Exchange server (2007 SP1) with the item ID in the subject line then print the label with that ID. So far I can read from Exchange and extract the ID number then send that to the report and have the report print i开发者_如何学Ct. Where I'm stuck is monitoring the inbox. How do I get the readEmail() method to fire automatically? There is no event to make this happen. I have to make it check the inbox by itself. The idea is so if we need a label printed, we can just send an email to this inbox and the label will print automatically. Only one person can print these and if he isn't here and someone needs a label, this lets him send an email and get the label printed.

private void readEmail()
{
   ExchangeService _mailService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
  _mailService.UseDefaultCredentials = true;
  _mailService.Url = new Uri("https://webmail.mydomain.com/ews/exchange.asmx");

  try
  {
    ItemView allItems = new ItemView(100);
    SearchFilter searchFilterInbox = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);
    Folder _inbox = Folder.Bind(_mailService, WellKnownFolderName.Inbox);

    if (_inbox.UnreadCount > 0)
    {
      FindItemsResults<Item> findResults = _inbox.FindItems(searchFilterInbox, allItems);
      List<Item> resultItems = new List<Item>();
      foreach (Item item in findResults.Items)
      {
        resultItems.Add(item);
        _mailService.LoadPropertiesForItems(resultItems, PropertySet.FirstClassProperties);
        cboPropertyTag.Text = item.Subject;
        GetReportVariables();
        reportType = "autoPrint";
        reportViewer rv = new reportViewer();
        rv.Show();
        item.Move(WellKnownFolderName.DeletedItems);
      }
    }
  }
  catch (ServiceVersionException)
  {
  }
}

Thanks in advance!

Paul


First idea that comes to mind is a System.Timers.Timer which regularly executes readEmail().

An other option would be a simply to use a Scheduled Task for an exe which runs every x minutes and executes your method.

0

精彩评论

暂无评论...
验证码 换一张
取 消