Outlook OLE

Outlook OLE

Postby Colin Haig » Wed Nov 04, 2009 8:58 am

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

Postby Colin Haig » Wed Nov 04, 2009 10:51 pm

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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Postby Jack » Thu Nov 05, 2009 8:40 pm

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

Thanks
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Outlook OLE

Postby Colin Haig » Thu Nov 05, 2009 11:23 pm

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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Postby Antonio Linares » Thu Nov 05, 2009 11:36 pm

Colin,

You can use [x]Harbour 'For Each':
Code: Select all  Expand view

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Outlook OLE

Postby Colin Haig » Sat Nov 07, 2009 3:26 am

Hi Antonio

Thanks for the sample code - I got it working.


Cheers

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

Re: Outlook OLE

Postby driessen » Sat Nov 07, 2009 8:42 pm

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Postby Colin Haig » Sun Nov 08, 2009 12:10 pm

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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Outlook OLE

Postby driessen » Mon Nov 09, 2009 10:51 am

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Postby nageswaragunupudi » Wed Nov 11, 2009 3:06 am

>>
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  Expand view
#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
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Outlook OLE

Postby Otto » Wed Nov 11, 2009 6:58 am

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

viewtopic.php?f=3&t=14111&p=72596&hilit=outlook#p72596



Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Outlook OLE

Postby nageswaragunupudi » Wed Nov 11, 2009 7:32 am

Mr Otto
Excellant !!
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Outlook OLE

Postby driessen » Wed Nov 11, 2009 6:47 pm

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Postby driessen » Mon Nov 23, 2009 6:59 pm

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  Expand view
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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Outlook OLE

Postby driessen » Tue Nov 24, 2009 2:24 pm

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests