Outlook OLE

Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Outlook OLE

Post by Colin Haig »

Hi

I can list the email subjects from an outlook inbox but how can I get the attachment details.

I would like to save the link to the attachment in a database eg c:\app\test.pdf or c:\app\test.xls

Cheers

Colin
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Post by Colin Haig »

Hi All

I have been searching the net for examples of what I am trying to do and
found the following but I dont know how to achieve this in FWH


For Each item In folder.Items 'For each item in the folder
For Each attachment In item.Attachments
'Every item, disregarding it's type, has the attachment collection
'We set the file name for this attachment using the path chosen by
'the user and the filename of the attachment
fileName = saveFolderPath + "\" & attachment.fileName
'We call the "SaveAsFile" method of the attachment object
'and pass "filename" as a parameter to save it to
'the desired location
attachment.SaveAsFile fileName
'We increment the attachment count variable
attachmentCount = attachmentCount + 1
Next attachment
Next item

Any help appreciated

Colin
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Re: Outlook OLE

Post by Jack »

Could you show the code that read the inbox of Outlook ??

Thanks
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Post by Colin Haig »

Jack

function ReadMail(aData)
local oOL,oNameSpace,oInbox,i := 0,cName := '',cEmail := '',nCount := 0,;
nNameSpace := 0,nLineCount := 0

asize(aData,0)

oOL := TOleAuto():New( "Outlook.Application" )

oNameSpace = oOL:Get( "GetNameSpace", "MAPI" )
oInbox = oNameSpace:Get( "GetDefaultFolder", "6" ) // 6 = Inbox-Folder

nCount := oInbox:ITEMS:Count()
for i := 1 to nCount
aadd(aData,oInbox:Items[ i ]:Subject)
nLineCount++
if nLineCount > 15
exit
endif
next
aShow(aData,2,5,25,85,'Test','Header')
return(aData)
//------------------------------------------------------------------------------------------------------//


Colin
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Outlook OLE

Post by Antonio Linares »

Colin,

You can use [x]Harbour 'For Each':

Code: Select all

for each item In folder:Items
   for each attachment In item:Attachments
      ...
   next
next
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Post by Colin Haig »

Hi Antonio

Thanks for the sample code - I got it working.


Cheers

Colin
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Post by driessen »

Hoi Colin,

I have been reading this topic with great attention.

Please, can you provide an example how you read the attachments and save them to disk ?

This is an issue in which I am very much interested. I started several topics on this subject and for the very first time, I read a topic which might provide us with a solution.

Thank you very much in advance for your help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Post by Colin Haig »

Hi Michel

I am still having issues with ole - it is crashing after diplaying the date after about 12 messages.


for each oItem In oInbox:Items
for each oAttach In oItem:Attachments
if valtype(oItem:ReceivedTime) == 'D'
MsgInfo(oItem:ReceivedTime)
else
MsgInfo(valtype(oItem:ReceivedTime))
endif
oAttach:SaveAsFile('c:\test\' + oAttach:filename)
next
next
This wil save all the attachments in your inbox - I am trying to get all the emails in
a date range

Hope this helps // must thank Antonio for his help

Colin
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Post by driessen »

Colin,

Thanks a lot for your help. I can read and save the attachments to my e-mails in the inbox now.

I have 2 more questions about Outlook and OLE.

1. Do you have any idea how to save a complete e-mail, attachments included ?
I'd like to be able to save my e-mails in seperate MSG-files.

2. Do you have any experience in synchronizing the Outlook-calendar ? I have a calendar in my application and I'd like to synchronize it with the Outlook-calendar. Any idea ?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Outlook OLE

Post by nageswaragunupudi »

>>
2. Do you have any experience in synchronizing the Outlook-calendar ? I have a calendar in my application and I'd like to synchronize it with the Outlook-calendar. Any idea ?
>>
I am using this function to post / modify / delete calendar entries. This code includes Test function

Code: Select all

#include 'fivewin.ch'

#DEFINE olFolderCalendar 9
#DEFINE olFolderContacts 10
#DEFINE olFolderDeletedItems 3
#DEFINE olFolderInBox 6
#DEFINE olFolderJournal 11
#DEFINE olFolderNotes 12
#DEFINE olFolderOutBox 4
#DEFINE olFolderSentMail 5
#DEFINE olFolderTask 13
#DEFINE olBusy 2
#DEFINE olPrivate 2
#DEFINE MAILITEM 0
#DEFINE IMPORTANCELOW 0
#DEFINE IMPORTANCENORMAL 1
#DEFINE IMPORTANCEHIGH 2

#define TEST

#ifdef TEST

function Main()

   local cID, lResult

   SET CENTURY ON
   SET DATE ITALIAN

   MsgInfo( 'Start' )
   CursorWait()

   cID := nil
   OutLookAppointment( @cID, Date() + 10 + 10/24, ;
                        'Subject for testing', ;
                        'Body for testing', 10, 30, .t. )

   msginfo( '|' + cID + '|', 'inserted' )

   if ! Empty( cID )
      OutLookAppointment( cID, Date() + 5 + 11/24 ) // Modify appointment
      msginfo( 'modified' )
      OutLookAppointment( cID, .t. ) // display appointment
      msginfo( 'displayed' )
      if MsgYesNo( 'Delete the appointment?' )
         OutLookAppointment( cID, .f. ) // delete appointment
         msginfo( 'deleted' )
      endif
   endif
   CursorArrow()
   MsgInfo( 'Done' )

return nil

#endif

function OutLookObject()

   local cApp  := 'OutLook.Application'
   local oOutLook

   TRY
      oOutLook          := GetActiveObject( cApp )
   CATCH
      TRY
         oOutLook       := CreateObject( cApp )
      CATCH
      END
   END

return oOutLook

function OutLookAppointment(  ;
            cID,              ; // See notes
            dDateTime,        ; // DateTime var of appointment
            cSubject,         ;
            cBody,            ;
            nDurationMinutes, ; // Duration in minutes, Default 5 mins
            nReminderMinutes, ; // Default no reminder
            lBusyStatus    )    // Default not busy

   /*
    * Should have minimum two parameters
    * if cID is nil and by ref, and 2nd parameter is date,
    *    cID is created and returned in the first param
    * if cID has valid ID and
    *    if second paramter is logical
    *      if .t. item is displayed
    *      if .f. item is deleted
    *    if second parameter is not logical
    *      appointment is modified and saved
    *
    * Returns success or failure as logical
    */

   local oOutLook, oItem, oNameSpace, oFolder, o
   local lEdited  := .t.
   local lSuccess := .f.

   if PCount() > 1

      TRY

         oOutLook       := OutLookObject()
         // oNameSpace & oFolder need not be used if the appln is runnning
         // This code runs whether the app is running or not

         oNameSpace  := oOutLook:GetNamespace( "MAPI" ) // Alternative oOutLook:Session is identical
         oFolder     := oNameSpace:GetDefaultFolder( olFolderCalendar ) // Constant value is 9

         if cID == nil
            if PCount() > 1 .and. dDateTime != nil
               // oItem    := oOutLook:CreateItem( 1 ) // not used bcuz this does not give EntryID if app is not running
               oItem       := oFolder:Items:Add()
               DEFAULT nDurationMinutes   := 5, ;
                       lBusyStatus        := .f.
            endif
         else
//          oItem       := oNameSpace:GetItemFromID( cID ) // Fails if the app is not running
//          Therefore this second approach, which works even when app is not running
            for each o in oFolder:Items
               if o:EntryID == cID
                  oItem := o
                  exit
               endif
            next o
         endif

         if oItem != nil
            if ValType( dDateTime ) == 'L'
               // Display or Delete
               if dDateTime         // 2nd parameter is true, Display
                  oItem:Display()
                  lSuccess    := .t.
               else                 // 2nd Parameter is false, Delete
                  oItem:Delete()
                  lSuccess    := .t.
               endif
            else
               // Create or Modify
               WITH OBJECT oItem
                  if ValType( dDateTime ) $ 'DT'
                     :Start      := dDateTime; lEdited := .t.
                  endif
                  if ValType( cSubject ) == 'C'
                     :Subject    := cSubject; lEdited := .t.
                  endif
                  if ValType( cBody ) == 'C'
                     :Body       := cBody; lEdited := .t.
                  endif
                  if ValType( nDurationMinutes ) == 'N'
                     :Duration   := nDurationMinutes; lEdited := .t.
                  endif
                  if ValType( lBusyStatus ) == 'L'
                     :BusyStatus := lBusyStatus
                  endif
                  if ValType( nReminderMinutes ) == 'N'
                     :ReminderMinutesBeforeStart   := nReminderMinutes
                     :ReminderSet                  := .t.
                     lEdited                       := .t.
                  endif
                  if lEdited
                     :Save()
                     if cID == nil
                        cID   := oItem:EntryID
                     endif
                     lSuccess := .t.      // Created or Modified
                  elseif cID == nil
                     // new item created but no valid data
                     oItem:Delete()
                  endif
               END
            endif
         endif // if oItem != nil

      CATCH
      END

   endif

return lSuccess

//------------------------------------------------------------------//
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Outlook OLE

Post by Otto »

Hello Michel,

I have an import button in my Fivewin programs. A click on the button opens a small window and you can drag the email from Outlook to this window.
The email gets converted to msg.

See my post:

drag and drop from outlook pure FIVEWIN solution

http://forums.fivetechsupport.com/viewt ... ook#p72596



Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Outlook OLE

Post by nageswaragunupudi »

Mr Otto
Excellant !!
Regards

G. N. Rao.
Hyderabad, India
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Post by driessen »

Thank you, Guys, for your fantastic proposals.

I know what to do tomorrow.

Joepie.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Post by driessen »

Hello,

I think I will succeed in building a synchronisation between the calendar in my application and the calendar in Outlook.
I also will be able to implement all the e-mails into my application.
All this was thanks to the help I got on this forum. Thank you all very much.

But I still have a question concerning Outlook and OLE.

How can I read the exact time of creation or the time of sending or the time of receiving of any e-mail message.

I tried one of these this code :

Code: Select all

oCalendar:Item:SentOn

oCalendar:Item:CreationTime

oCalendar:Item:ReceivedTime
Unfortunately, these codes only result into date, but I'm not able to read the exact time.

Anyone any idea ?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Post by driessen »

Hello,

Because my question is quite urgent, I put a small repitition.

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Post Reply