Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. i want delete attachment when new mail receiving.....
2. so i use NewmailEx event.....and also tried Newmail event.....
3. i open the outlook --> send a mail to my outlook mail -->the event get fired -->but the received mail is not shown in my unreaded mail i.e, c# coding did't get the received mail (this happen only for the first mail..after closing and opening of outlook..from the second mail the operation works correctly)
4. i attach my code below
C#
private void ThisAddIn_Startup(object sender, System.EventArgs e)
       {
           this.Application.NewMail += new Microsoft.Office.Interop.Outlook
              .ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
       }
       private void ThisApplication_NewMail()
       {
           Outlook.MAPIFolder inBox = this.Application.ActiveExplorer()
               .Session.GetDefaultFolder(Outlook
               .OlDefaultFolders.olFolderInbox);
           Outlook.Items inBoxItems = inBox.Items;
           Outlook.MailItem newEmail = null;
           inBoxItems = inBoxItems.Restrict("[Unread] = true");

           foreach (object collectionItem in inBoxItems)
           {
               newEmail = collectionItem as Outlook.MailItem;
               if (newEmail != null)
               {
                   if (newEmail.Attachments.Count > 0)
                   {
                       for (int i = 1; i <= newEmail
                          .Attachments.Count; i++)
                       {
                           newEmail.Attachments[1].Delete();

                       }
                   }
               }
           }
       }


5. pls help me to read he first mail.....when outlook was open...
6. thank u in advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900