3
以下是我的...以编程方式监视Exchange收件箱和打印标签
我有一个跟踪条码类型标签的程序。我可以选择数据库中的一个项目并为其打印标签。我添加了将电子邮件发送到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)
{
}
}
在此先感谢!
保罗
谢谢。我添加了一个监视器对象,将其设置为30秒(当我们运行时会使它更长),启动它,当它运行时说,运行方法如上。我在开始时停止了计时器,并重置,然后在最后开始计时。问题是现在当我访问窗体上的对象时,我得到一个交叉线程错误。所以我想弄清楚如何获取数据,而不是依赖表单。 – 2011-02-07 23:23:49