title: how to mark unread email in outlook to read using visual studio 2013
body: <p>Hello I'developing the outlook addin which will automate the task of extracting unread emails with no attachment in a folder &amp; extracting attachments to the folder.However I'm able to code the extracting of attachments from emails to folder but I realized two issues that I should have pointed out. Some emails may contain more than 1 attachment and some attachments may have the same filename (and need to be auto renamed when extracted to prevent overwriting).so I'm not able to understand how to code it?Also I want code for the emails with no attachments retrieved in a specific folder.Please help with this. Below is the code which extract attachment in a folder from emails.
  Public Class ThisAddIn</p>
  
  <pre><code>Private Sub ThisAddIn_Startup() Handles Me.Startup
      Dim inbox As Outlook.MAPIFolder = Me.Application.ActiveExplorer.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
      Dim unreadItems As Outlook.Items = inbox.Items.Restrict("[Unread]=true")
      Dim inboxItems As Outlook.Items = inbox.Items.Restrict("[Unread]=true")
      Dim newEmail As Outlook.MailItem
      MsgBox(String.Format("Unread items in Inbox = {0}", unreadItems.Count))
      Try
          For Each collectionItem As Object In inboxItems
              newEmail = TryCast(collectionItem, Outlook.MailItem)
              If newEmail IsNot Nothing Then
                  If newEmail.Attachments.Count &gt; 0 Then
                      For i As Integer = 1 To newEmail.Attachments.Count
                          For j As Integer = i + 1 To newEmail.Attachments.Count
                              ' Dim saveAttachment As Outlook.Attachments = newEmail.Attachments(i)
                              If newEmail.Attachments(i).FileName.Equals(newEmail.Attachments(j).FileName) Then
                                  newEmail.Attachments(j).SaveAsFile("C:\Attachment\Copy\" &amp; (newEmail.Attachments(j).FileName))
  
                                  Exit For
                              End If
                          Next (j)
                          newEmail.Attachments(i).SaveAsFile("C:\Attachment\" &amp; (newEmail.Attachments(i).FileName))
                      Next (i)
                  End If
  
              End If
  
          Next collectionItem
  
      Catch ex As Exception
          If Left(ex.Message, 11) = "Cannot Save" Then
              MsgBox("Create Folder C:\Attachment")
          End If
  
      End Try
  
  
  
  End Sub
  </code></pre>