Skip to main content

Using Visual FoxPro to manipulate Outlook Inbox messages

One of the Outlook Blogs made a note of a tool called QuickMailSort,
something that was supposed to organize all your emails by the Company for
each contact.

I downloaded and tried it out. Well - it didn't quite do what it said it
would do so I tossed it but said "maybe I should do it myself"

The following piece of code will run through your inbox folder and create
sub-folders for every company name in the contact file and then move the
messages in there. I use company name so that all messages from different
people at a single company can go in there. My first pass took about 15
seconds and sorted through about 1000 messages. I'm happy.

Here's the code.

** Create a link to Outlook and folders

** Note - I'm going directly against Folder names here because I have about
10 different PSTs in my Outlook configuration

lo = CREATEOBJECT("outlook.application")
loSpace = lo.GetNameSpace("MAPI")
loContacts = loSpace.Folders("Mailbox").Folders("Contacts")

loFolder = loSpace.Folders("Mailbox").Folders("Inbox")

** Go BACKWARDS through messages otherwise you won't find them.

FOR lni = loFolder.Items.Count TO 1 STEP -1
loMsg = lofolder.items(lni)

*** Yes I'm using TRY CATCH here because Outlook's Find sometimes bombs on
really big email addresses
TRY
loFind =
loContacts.Items.Find("[Email1Address]="+lomsg.SenderEmailAddress)
IF NOT ISNULL(loFind)
** I'm only moving them if they have a company
IF NOT EMPTY(loFind.CompanyName)
** We do another try here so we can create the Folder name
TRY
lo = loFolder.Folders(loFind.Companyname)
CATCH
loFolder.Folders.Add(loFind.CompanyName)
ENDTRY
loMsg.Move(loFolder.Folders(loFind.Companyname))
ENDIF
ENDIF
CATCH
** Do nothing
ENDTRY

ENDFOR
RETURN


Comments

Popular posts from this blog

Blogs and RSS come to Microsoft.com

MS has just introduced their portal and it's pretty comprehensive. Nothing quite like learning that some people use AIM instead of MSN messenger, or that there really may be a need for supporting 4 monitors ( Cyrus Complains ) However, it's really a great sign that MS is serious about supporting the blogging community which seems to have um, exploded in size in the past year. Blogs and RSS come to Microsoft.com

FoxInCloud Stats

FoxInCloud sent this link a while back about their statistics regarding visits to their site: http://foxincloud.com/blog/2017/12/27/VFP-community-lessons-from-foxincloud-site.html What's interesting here is the breakdown of people. Yes, I think it's understandable that the Fox community is getting older. Another factor is the growth of the mobile and web environments taking over development. These environments really do push people towards the newer non-SQL or free SQL/hosted environments but more towards hosted storage options like Amazon and Google. A tool like FoxInCloud that helps MOVE existing applications to the cloud inherently competes with those environments. But FoxInCloud also allows developers to extend their application further by giving them a starting point using Javascript and the basic CSS (such as Bootstrap). If you're not rebuilding your application from scratch, it's certainly a great step forward. FoxPro VFP

5 Great Reasons to attend Virtual FoxFest

What's coming up? Virtual FoxFest is coming up soon (sessions start October 14th). Like last year, the conference is entirely virtual yet includes great breakdown rooms and sessions to add that nice one-on-one feel that you get in person. It's also staggered so you can choose which days you want to attend - October 14th, 20th and 26th. This is great if you can't break away for a consecutive three days. But really, I've gone through the sessions and I see five great sessions that I'm eager to check out. 1. A Decade of Thor (Rick Schummer) Thor has been an extension for Visual FoxPro that many developers swear by, yet many don't know even exists. Visual FoxPro's built-in extensions are great but Jim Nelson's Thor supercharges your IDE. I can't believe it's been ten years - so Rick's session should be able to not just whet your appetite but give you all the reasons you should be using it. 2. VFP C++ compiler.  Last year, we saw DotNetX as well