Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

need vb.net code to delete e-mails from custom outlook folder

Posted on 2011-03-01
3
Medium Priority
?
295 Views
Last Modified: 2012-05-11
have hundreds of thousands of e-mail messages that need to be deleted
doing it manually would take a long long time

trying to automate using vb.net
folder containing e-mails is located under

Deleted Items /  Notifications

-Alex
0
Comment
Question by:AlexF777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 35009037
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 35009410
here's the code for you:
Dim OutlookApp As New Application()
Dim exp As _Explorer = OutlookApp.ActiveExplorer()

For Each st As Store In exp.Session.Stores
	If st.DisplayName.ToLower().StartsWith("mailbox") Then
		Dim rootFolder As MAPIFolder = st.GetRootFolder()
		Dim parentFolder As MAPIFolder = rootFolder.Folders.Cast(Of MAPIFolder)().Where(Function(n) n.Name = "Deleted Items").FirstOrDefault()
		Dim folder As MAPIFolder = parentFolder.Folders.Cast(Of MAPIFolder)().Where(Function(n) n.Name = "Notifications").FirstOrDefault()
		folder.Delete()
		Try
			parentFolder.Folders.Add("Notifications", OlDefaultFolders.olFolderInbox)
		Catch ex As System.Exception
			Console.WriteLine(ex.Message)
		End Try
		Exit For
	End If
Next

exp.Close()

Open in new window

0
 

Author Comment

by:AlexF777
ID: 35010979
getting 'NullReferenceException was unhandled'
Object reference not set to an instance of an object
 
after reaching

 For Each st As Store In exp.Session.Stores
0

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question