Hi
I use Aspose.Email 6.0. I write bllow code to get notification on receive new emial. but this code not work and event handlers never call:
eswClient.InboxFolderServerNotifications += eswClient_InboxFolderServerNotifications;
eswClient.DeletedItemsFolderServerNotifications += eswClient_DeletedItemsFolderServerNotifications;
Hi Freydoon,
Thank you for contacting Aspose support team.
I have checked this feature using Aspose.Email for .NET 6.5.0 and found it working. You may please give a try to the following sample code and let us know the feedback.
const string mailboxUri = "https://exchange.domain.com/ews/Exchange.asmx";
const string domain = @"";
const string username = @"username123";
const string password = @"password";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient eswClient = EWSClient.GetEWSClient(mailboxUri, credentials);
String subject = "NETWORKNET-34103 - " + Guid.NewGuid().ToString();
MailMessage message =
new MailMessage("username123", "username123", subject, "NETWORKNET-34103 Implements Exchange Events notifications functionality");
bool messageFound = false;
eswClient.NotificationsCheckInterval = 10 * 1000;
eswClient.InboxFolderServerNotifications += delegate (object sender, ServerNotificationEventArgs e) { messageFound = true; };
eswClient.DeletedItemsFolderServerNotifications += delegate (object sender, ServerNotificationEventArgs e) { messageFound = true; };
eswClient.UpdateSubscription();
messageFound = false;
eswClient.Send(message);
Thread.Sleep(10000);
if(messageFound == true)
{
Console.WriteLine("Server notification set it to true for receiving");
}
messageFound = false;
//Declare variable for getting specified custom folder uri
ExchangeMailboxInfo mailbox = eswClient.GetMailboxInfo();
//Get all the messages info from the target Uri
ExchangeMessageInfoCollection messages = eswClient.FindMessages(mailbox.InboxUri);
//Parse all the messages info collection
foreach (ExchangeMessageInfo info in messages)
{
if (info.Subject == subject)
{
string strMessageURI = info.UniqueUri;
eswClient.DeleteMessage(strMessageURI, true);
}
}
Thread.Sleep(10000);
if (messageFound == true)
{
Console.WriteLine("Server notification set it to true for deletion");
}
Hi
Thanks for the prompt reply.
Your sample code work fine. How I can get received message or its messageId in InboxFolderServerNotifications event?
Hi Freydoon,
You may please use following sample code once InboxFolderServerNotifications is received:
ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.HasNoFlags(ExchangeMessageFlag.IsRead);
MailQuery query = builder.GetQuery();
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, query);
if (messageInfoCol.Count >= 1)
Console.WriteLine("There are messages in Inbox");
else
Console.WriteLine("Error! No message in Inbox");