?
Solved

Must Get Outlook E-mail Data into External Desktop Applicaiton - Can You Help Complete My Code?

Posted on 2007-10-10
10
Medium Priority
?
252 Views
Last Modified: 2008-01-09
I'm building a Flash application that needs to import email data from Outlook on sync operations, namely 1) The email body of emails with a given string existing in the subject-line, and 2) all attachments on the message.  Since I don't want the user to be required to leave my application while the sync is taking place, my idea is send commands to outlook via a remote object with VBS destination properties, as follows (just an example):
---------------------------------------------------------------------------------------
    <mx:RemoteObject id="RO" destination="MyRemoteObjectDest" fault="Alert.show(event.fault.faultstring), 'Error'">

        <mx:method name="getOutlookData">
            <mx:arguments>
                ...
            </mx:arguments>
        </mx:method>
    </mx:RemoteObject>
---------------------------------------------------------------------------------------
The "getOutlookData" is a VBS file that is meant to write Outlook data to a folder where the application can access it.  If I could send the Outlook data back though the remote object for use inside my actionScript, my application would handle the sync entirely...  Since I don't think it is possible to save references to possible email attachments and then perform 'save-as' from my app, the VBS is instead meant to create folders for each message, store the message body in a text file inside the newly created folder, then save any attachments into the folder too.  The VBS will return a Boolean indicating when operations are complete so the app can begin importing data.

The problem here is this: 1) I don't know if the VBS can be called this way or how it receives parameters if it can, 2) My VB skills are slow and I have to hunt through MSDN2 for functions while my extra-project time is limited.

My questions to you are:

1) Is there a better, simpler approach to what I'm trying to do?  If so, what is that?
2) If not, what functions do you think are best for this operation (please show where)
3) Can you pass parameters into a VBS file triggered this way?  If so, how?

Thanks.  This isn't super urgent but I'd like to get back to this soon; just need a brain-break.  Still, it's a big question, hence the point value.  Code appears below:
0
Comment
Question by:JaeWebb
  • 5
  • 4
9 Comments
 

Author Comment

by:JaeWebb
ID: 20051511
Forgot to include the VBS file in-progress:
-------------------------------------------------------------------------------

Sub getOutlookData()

      Dim outlookProxy As Object
      Dim folder As Object
      Dim message As Object
      Dim tempStr As String
      Dim tempFolderName As String
      Dim index As Long
      
      'Can these values be passed into the script insead, ie. 'getOutlookData(keyTHQ, keyTicketNum, targetDir)'?
      Const keyTHQ As String = "(THQ-assignment)"
      Const keyTicketNum As String = "Ticket #"
      Const targetDir As String = "C:\Resources\"
      
      Set outlookApp = CreateObject("Outlook.Application")
      Set folder = outlookProxy.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
      
      'Search each message in the designated folder for subject-line data containing searchkey
      For Each message in folder.Items
            If (InStr(1, message.Subject, keyTHQ) Then
                  
                  'Parse subject-line data into processing variables
                  tempStr = message.Subject
                  index = InStr(1, message.Subject, keyTicketNum)
                        'Count characters in keyTicketNum and add to index value; index should equal point after last character of keyTicketNum
                        'no such function as 'countChar' - it's just an idea at this point
                  index = index + countChar(keyTicketNum)
                        'get copy of subject-line with all characters to the left of the index-point stripped off, resulting in no spaces at front of string
                  tempStr = LTrim(tempStr(index))
                        'delete all characters after the first space from tempStr
                  tempStr = Split(tempStr, " ", 1, 1)
                  
                  
                  'Create messageFolder in target directory; messageFolder's name is equal to tempStr
                  
                  'Create text-file called "messagelog.txt" in messageFolder.  If messagelog exists, overwrite, then store
                  'message.Body data as text in messagelog.txt
                                    
                  
                  'If message has attachments, check if attachment exists in  messageFolder.  If attachment does not exist
                  'in message folder, save copy of attachment in messageFolder
      
      
      'Return a Boolean value upon completion(true if script runs successfully, false if not)
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20052646
Hi there,  I can tell you that values can be passed to a VBS file, and collected using the WScript.Arguments collection.

For example, you can run a command like so:
wscript yourscript.vbs value1 value2

then the VBScript will be:
'============
strParam1 = WScript.Arguments.Item(0)
strParam2 = WScript.Arguments.Item(1)

Execute("GetOutlookData(" & strParam1 & "," & strParam2 & ")"

Sub GetOutlookData(sParam1, sParam2)
      MsgBox "Parameter 1: " & sParam1 & VbCrLf & "Parameter 2: " & sParam2
End Sub
'============

As far as the Outlook bits go, I don't use Exchange, and so can't really help you there....

Regards,

Rob.
0
 

Author Comment

by:JaeWebb
ID: 20053164
Rob,

Thanks for your comments.

Interesting.  What environment could I call this script from (wscript yourscript.vbs value1 value2)?  It looks like a command-line type statement.  Do you know if that is the same affect as calling the yourscript.vbs file from an XML/Remote Object doc (same as clicking an exe from what I understand), or will I explictly have to run this in at a command prompt?

BTW, I don't use Exchange either.  This post is only about triggering a VB script from an application external to MS Office (Flash/AIR App).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 65

Expert Comment

by:RobSampson
ID: 20054106
>> What environment could I call this script from?

Yes, it is a shell command.  From within your Flash application, can you "shell" a command?  To do something like that in VBScript (just to illustrate), you would use:
Set objShell = CreateObject("WScript.Shell")
objShell.Run "cscript yourscript.vbs value1 value2", 1, True

but whatever you use in Flash to execute the VBS, you can try without the cscript bit, and just see if you get the parameters passed, but otherwise, plug in the cscript (or wscript if you don't want the command prompt version), and see what happens.

Just make sure than in your VBS file you are obtaining the WScript.Arguments items.

Regards.

Rob.
0
 

Author Comment

by:JaeWebb
ID: 20102048
Rob - I read your commentary just after you posted but I forgot to let you know that 1) I appreciate your response - it looks good and 2) yes, Flash has a Shell class but I'm not totally sure on how it should be used yet.  When I get the chance, which should be before the end of the week, I'm going to study it a bit, test your solution and get back to you.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 20106579
Hi there, it looks like
fscommand("exec","programname.exe")
is what you're after, but separate your arguments by tabs instead of spaces....

http://www.beyondflash.com/content/ch02.htm

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20293736
DanRollins, judging by the link I posted, fsCommand seems to do the job in Flash.....

Regards,

Rob.
0
 

Author Comment

by:JaeWebb
ID: 20296581
Rob,

I was taken off of this project at work so I didn't get back to you when I said I would.  Coincidently I just put myself back on project so I'll be testing either tonight or tomorrow.  Still, without testing, I know your solution is correct.  After seeing your response I did a search for fsCommand, which I thought was just ol'school flash, but I found a reference to it in ActionScript 3.0:

http://livedocs.adobe.com/flex/2/langref/flash/system/package.html

Thanks a bunch, Rob!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20296619
Great, no problem.  Thanks for that....

Regards,

Rob.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

615 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