以编程方式监控 Exchange 收件箱并打印标签

发布于 2024-10-16 01:56:15 字数 1533 浏览 4 评论 0原文

这就是我所拥有的...

我有一个程序可以跟踪条形码类型标签。我可以在数据库中选择一个项目并为其打印标签。我添加了以下功能:将电子邮件发送到我们的 Exchange 服务器 (2007 SP1) 上的特定收件箱,主题行中包含项目 ID,然后打印包含该 ID 的标签。到目前为止,我可以从 Exchange 中读取并提取 ID 号,然后将其发送到报告并让报告打印它。我陷入困境的是监视收件箱。如何让 readEmail() 方法自动触发?没有任何事件可以实现这一点。我必须让它自己检查收件箱。我们的想法是,如果我们需要打印标签,我们只需向此收件箱发送电子邮件,标签就会自动打印。只有一个人可以打印这些,如果他不在这里并且有人需要标签,这可以让他发送一封电子邮件并打印标签。

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)
  {
  }
}

提前致谢!

保罗

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 it. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森罗 2024-10-23 01:56:15

我想到的第一个想法是 System.Timers。定时器定期执行readEmail()

另一种选择是简单地使用 exe 的计划任务,该任务每 x 分钟运行一次并执行您的方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文