Outlook Fun With Scriptom

It is soo true that if you work for a startup you end up wearing multiple hats. I work for a very small startup and I wear more hats that the Queen of England. One of those hats is of a Visual Basic developer. Most business applications are not fancy or web two point ooh-y, they usually involve some charts, some graphs, and some integration with Microsoft Office products.

As most script kiddies know, with a little Visual Basic code you can write scripts to open, write, and send emails, generate excel documents, print word documents, and so much more. Fore example, here is a little bit of vbs code to automate the send button (now if you can automate running the script):

[source:vbs]
Set objOutlook = CreateObject(“Outlook.Application”)
Set objNamespace = objOutlook.GetNamespace(“MAPI”)

‘ Need to have open a new email window for the following
Set objInspector = objOutlook.ActiveInspector
Set objMailItem = objInspector.CurrentItem

‘ Send the email, after the user presses the okay
‘ button on the confirmation dialog
objMailItem.Send
[/source]

Now, if you want to pop up a message dialog with the subject of the last email you received, just run the following lines of code:

[source:vbs]
Const olFolderInbox = 6
Const olFolderSentMail = 5

Set objOutlook = CreateObject(“Outlook.Application”)
Set objNamespace = objOutlook.GetNamespace(“MAPI”)

Set objFolder = objNamespace.GetDefaultFolder(olFolderSentMail)
MsgBox “Subject: ” & objFolder.Items.GetLast.Subject
[/source]

I have a few more example of Visual Basic code manipulating Microsoft Office products here. If you want to run similar COM code but in Java you can do so using Groovy and Scriptom. I have already mentioned Scriptom before so I will refer you to that post.

Technorati Tags: , , , , , , ,