COMatePlus Outlook Question

Just starting out? Need help? Post your questions and find answers here.
Joestes
User
User
Posts: 25
Joined: Thu Mar 19, 2009 12:42 pm
Location: Utrecht, The Netherlands

COMatePlus Outlook Question

Post by Joestes »

Hi,

I downloaded COMatePlus and want to create an appointment in Outlook.

I created the appointment/meeting like this:

Code: Select all

XIncludeFile "C:\Program Files\PureBasic\Include\COMatePlus.pbi" 

Define.COMateObject OutlookObject.COMateObject, olMsg.COMateObject

sub.s     = "Meeting"
standard.s= "Hello"
loc.s     = "My room"

OutlookObject = COMate_CreateObject("Outlook.Application") 
If OutlookObject 
 olMsg = OutlookObject\GetObjectProperty("CreateItem(1)") 
 If olMsg 
  olMsg\SetProperty("Subject='"+sub+"'") 
  olMsg\SetProperty("Location='"+loc+"'") 
  olMsg\SetProperty("Start='1/1/2012 1:30:00 PM'") 
  olMsg\Invoke("Display") 
  olMsg\Release() 
 Else 
  MessageRequester("Sorry", COMate_GetLastErrorDescription()) 
 EndIf 
 OutlookObject\Release()  
Else 
 MessageRequester("Sorry - CreateObject", COMate_GetLastErrorDescription()) 
EndIf
I was wondering if anyone else managed to add recipients...?

On Microsoft's pages I found it works like this:

Code: Select all

Set myRequiredAttendee = myItem.Recipients.Add("Joost _ Anbeek")
myRequiredAttendee.Type = olRequired
Set myOptionalAttendee = myItem.Recipients.Add("Henk _ de Vries")
myOptionalAttendee.Type = olOptional
Set myResourceAttendee = _myItem.Recipients.Add("Conference Room B")
myResourceAttendee.Type = olResource
Is there any way to do this in Purebasic?

Thanks in advance!!
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: COMatePlus Outlook Question

Post by spikey »

Code: Select all

IncludeFile "COMatePLUS.pbi"

Define OutlookObject.COMateObject, olMsg.COMateObject, olRecip.COMateObject
Define.I flagSuccess

sub.s     = "Meeting"
standard.s= "Hello"
loc.s     = "My room"

OutlookObject = COMate_CreateObject("Outlook.Application")
If OutlookObject
  olMsg = OutlookObject\GetObjectProperty("CreateItem(1)")
  If olMsg
       
    olMsg\SetProperty("Subject='"+sub+"'")
    olMsg\SetProperty("Location='"+loc+"'")
    olMsg\SetProperty("Start='1/1/2012 1:30:00 PM'")
    
    ; Required attendee
    olRecip = olMsg\GetObjectProperty("Recipients\Add('Joost _ Anbeek')")
    If olRecip
      olRecip\SetProperty("Type=1")
      flagSuccess = #True
      
    Else
      flagSuccess = #False
      
    EndIf
    
    If flagSuccess
      
      ; Optional attendee
      olRecip = olMsg\GetObjectProperty("Recipients\Add('Henk _ de Vries')")
      If olRecip
        olRecip\SetProperty("Type=2")
      Else
        flagSuccess = #False
      EndIf
      
      ; Resource
      olRecip = olMsg\GetObjectProperty("Recipients\Add('Conference Room B')")
      If olRecip
        olRecip\SetProperty("Type=3")
      Else
        flagSuccess = #False
      EndIf
      
    EndIf
    
    olMsg\Invoke("Display")
    olMsg\Release()
    olRecip\Release()
    
    If flagSuccess = #False
      MessageRequester("Sorry", "Add recipients failed. The security confirmation may have been cancelled.")  
    EndIf
    
  Else
    MessageRequester("Sorry", COMate_GetLastErrorDescription())
  EndIf
  OutlookObject\Release() 
Else
  MessageRequester("Sorry - CreateObject", COMate_GetLastErrorDescription())
EndIf
Note that the attempt to add contacts/resources via the COM interface is regarded as a potential malware activity and triggers a security confirmation in Outlook which the user has the option to cancel. If so, these methods will fail.
Joestes
User
User
Posts: 25
Joined: Thu Mar 19, 2009 12:42 pm
Location: Utrecht, The Netherlands

Re: COMatePlus Outlook Question

Post by Joestes »

Thanks a lot!

This is exactly what I needed!
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: COMatePlus Outlook Question

Post by dige »

@spikey: thank you for that nice example of creation an outlook appointment.

But how can I read appointments from calendar? Can you help?

Ciao dige
"Daddy, I'll run faster, then it is not so far..."
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: COMatePlus Outlook Question

Post by dige »

Found in the German forum: http://www.purebasic.fr/german/viewtopi ... 16&t=29223

Code: Select all

; by dietmar

#olFolderCalendar          = 9
#olFolderContacts          = 10
#olFolderSuggestedContacts = 30


Global Outlook.COMateObject, NameSpace.COMateObject, Folder.COMateObject, Items.COMateObject, Termin.COMateObject, TerminWiederholung.COMateObject

Outlook = COMate_CreateObject("Outlook.Application")
If Outlook
  NameSpace = Outlook\GetObjectProperty("GetNamespace(" + Chr(39) + "MAPI" + Chr(39) + ")")
  If NameSpace
    Folder = NameSpace\GetObjectProperty("GetDefaultFolder(" + 9 + ")")
    If Folder
      Items = Folder\GetObjectProperty("Items")
      Items\SetProperty("Item\Sort" + Chr(39) + "[Start] >= '09/09/2016'"  + Chr(39))
      Items\SetProperty("items\IncludeRecurrences = True)")
      If Items
        For i=1 To i+1
          Termin = Items\GetObjectProperty("Item("+Str(i)+")" )
          TerminWiederholung = Items\GetObjectProperty("Item("+Str(i)+")\GetRecurrencePattern" )
          If Not Termin: Break: EndIf
          Debug Termin\GetStringProperty("Subject") + ", " + Termin\GetStringProperty("Start") + " bis " + Termin\GetStringProperty("End") + " Uhr"
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\RecurrenceType")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\RecurrenceType")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\DayOfWeekMask")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\MonthOfYear")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\Instance")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\Occurrences")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\Duration")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\PatternStartDate")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\StartTime")
          ; Debug TerminWiederholung\GetStringProperty("Item("+Str(i)+")\EndTime")
          
        Next
        If Termin   : Termin\Release()  : EndIf
        If Items    : Items\Release()    : EndIf
        If Folder   : Folder\Release()   : EndIf
        If NameSpace: NameSpace\Release(): EndIf
        If Outlook  : Outlook\Release()  : EndIf
      EndIf
    EndIf
  EndIf
EndIf
"Daddy, I'll run faster, then it is not so far..."
Post Reply