I am trying to develop an add-in for Outlook. In that I want remove attachment when a new mail is received.

So I call my function on the `NewMailEx` event. It is working fine. In that function I try to find unread mails in the Outlook inbox. From those I remove the attachments.

My problem is: when I open Outlook, the first mail I received is not showing in the inbox (not in outlook c# code), so I can't remove the attachment from that mail.

From the second mail (after the first mail), I can get the received mail, so I can remove the attachments.

Whenever I close and reopen Outlook, the first mail I receive gives this problem.

At the first mail received there is no unread mail.

```
private void Application_NewMailEx(object Item)
{
    string senderEmailid = string.Empty;
    outlookNameSpace = this.Application.GetNamespace("MAPI");
    Outlook.Application myApp = new Outlook.Application();
    Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
    Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    Outlook.Attachments attachments;
    int test = myInbox.Items.Count;

    Microsoft.Office.Interop.Outlook.Recipients recipients = ((Outlook.MailItem)myInbox.Items[test]).Recipients;
    Outlook.Items unreadItems = myInbox.Items.Restrict("[Unread]=true");
    if (unreadItems.Count > 0)
    {       
        foreach (Outlook.MailItem mail in unreadItems)
        {
            Outlook.Recipient recip;
            Outlook.ExchangeUser exUser;
            string sAddress;

            if (mail.SenderEmailType.ToLower() == "ex")
            {
                recip = Globals.ThisAddIn.Application.GetNamespace("MAPI").CreateRecipient(mail.SenderEmailAddress);
                exUser = recip.AddressEntry.GetExchangeUser();
                sAddress = exUser.PrimarySmtpAddress;
            }
            else
            {
                sAddress = mail.SenderEmailAddress.Replace("'", "");
            }
            string[] emailAddressPart = sAddress.Split('@');
            string strSenderDomain = emailAddressPart[1];
            if (lstDomain.Any(item => item.Contains(strSenderDomain)))
            {
                attachments = mail.Attachments;
                int nAttachmentCount = mail.Attachments.Count;
                if (nAttachmentCount > 0)
                {
                    int j = nAttachmentCount;
                    for (int i = 1; i <= nAttachmentCount; i++)
                    {
                        mail.Attachments[j].Delete();
                        j--;
                    }
                }
            }
        }
    }           
}

```