Here is what I have ...
I have a program that tracks barcode type labels. I can select an item in the database and print a shortcut for it. I am adding the ability to send email to a specific mailbox on our Exchange server (2007 SP1) with the item ID in the subject line, and then print a shortcut with that ID. For now, I can read from Exchange and extract the ID number, and then send it to the report and print the report. Where I'm stuck, keeps track of incoming. How to automatically run the readEmail () method? There is no event for this to happen. I have to check it myself. The idea is that if we need to print a shortcut, we can simply send an email to this inbox, and the shortcut will print automatically. Only one person can print them, and if he is not here,and someone needs a shortcut, this will allow him to send an email and print the shortcut.
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)
{
}
}
!