vb script to grab outlook inbox mail and append date sent to a file

Posted on 2004-11-03
Last Modified: 2008-03-17
I want to write a vb script to poll at an outlook inbox, open any unread mail, grab the date on there, and write that date and time value to a file.

The script will keep polling until it is killed. So that means it will need to keep appending to the output file one line of date and time for every incoming mail...

any help would be greatly appreciated!
Question by:jade03

    Author Comment

    Ok, I think I figured out works halfway now...I can grab mail from the inbox and grab specific info from that mail and send it to a file...problem is, I still can't seem to grab the date and time from that particular mail...apparently folderItem.Sent is not it...

    any ideas?
    LVL 16

    Expert Comment

    The property you are looking for is folderItem.SentOn


    LVL 16

    Accepted Solution

    If you declare a reference to the Microsoft Scripting Runtime, in your project, you can access the FileSystemObject.

    Now, declare two objects as Public, e.g.:

         Public objFSO as Scripting.FileSystemObject
         Public objTS as Scripting.TextStream

    Since these values are public, they should be available to all procedures you write.  Now, you can set these up, initially, with:

         Set objFSO = CreateObject("Scripting.FileSystemObject")
         Set objTS = objFSO.CreateTextFile("x:\mypath\mylogfile.log", ForAppending, True)

    Whenever you want to write to a file, use:

         objTS.WriteLine folderItem.SentOn

    When its time to end your program, use


    to close and save the file.


    LVL 16

    Expert Comment

    Alternatively, you can do it the old-fashioned way:

    Every time you want to write to the log file, you can use:

           Open "x:\mypath\mylogfile.log" For Append As #1
                 Print #1, folderItem.SentOn
           Close #1

    to open, write and save the file, each time you write to it.

    If you can get it working, however, my previous suggestion should be less resource-intensive (not that it should matter too much)


    Author Comment

    Great! Thanx, J! :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now