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

Programmers vs. Developers vs. Architects

I received an email this morning from Brandon Savage 's newsletter. Brandon's a PHP guru (works at Mozilla) but his newsletter and books have some great overall perspectives for developers of all languages. However, this last one (What's the difference between developers and architects?) kind of rubs me the wrong way. Either that, or I've just missed the natural inflation of job descriptions. (maybe, it's like the change in terminology between Garbage man and Waste Engineer or Secretary and Office Administrator) So maybe it's just me - but I think there's still a big difference between Programmer, Developer and then of course, architect. The key thing here is that every role has a different perspective and every one of those perspectives has value. The original MSF create roles like Product Manager, Program Manager, Developer, Tester, etc - so every concept may pigeon hole people into different roles. But the statements Brandon makes are often distinction

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