File: w_main.srw
Size: 20283
Date: Thu, 02 Feb 2023 03:04:54 +0100
$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type cb_newemail from commandbutton within w_main
end type
type cb_print from commandbutton within w_main
end type
type cb_saveas from commandbutton within w_main
end type
type cb_delete from commandbutton within w_main
end type
type ddlb_folder from dropdownlistbox within w_main
end type
type ole_html from u_web_browser within w_main
end type
type cb_cancel from commandbutton within w_main
end type
type cb_retrieve from commandbutton within w_main
end type
type dw_inbox from datawindow within w_main
end type
end forward

global type w_main from window
integer width = 2866
integer height = 2708
boolean titlebar = true
string title = "Outlook Automation Example"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cb_newemail cb_newemail
cb_print cb_print
cb_saveas cb_saveas
cb_delete cb_delete
ddlb_folder ddlb_folder
ole_html ole_html
cb_cancel cb_cancel
cb_retrieve cb_retrieve
dw_inbox dw_inbox
end type
global w_main w_main

type variables
// OlDefaultFolders Enumeration
Constant Integer olFolderDeletedItems = 3
Constant Integer olFolderOutbox = 4
Constant Integer olFolderSentMail = 5
Constant Integer olFolderInbox = 6
Constant Integer olFolderCalendar = 9
Constant Integer olFolderContacts = 10
Constant Integer olFolderJournal = 11
Constant Integer olFolderNotes = 12
Constant Integer olFolderTasks = 13
Constant Integer olFolderDrafts = 16
Constant Integer olPublicFoldersAllPublicFolders = 18
Constant Integer olFolderConflicts = 19
Constant Integer olFolderSyncIssues = 20
Constant Integer olFolderLocalFailures = 21
Constant Integer olFolderServerFailures = 22
Constant Integer olFolderJunk = 23
Constant Integer olFolderRssFeeds = 25
Constant Integer olFolderToDo = 28
Constant Integer olFolderManagedEmail = 29

// OlBodyFormat Enumeration
Constant Integer olFormatHTML = 2
Constant Integer olFormatPlain = 1
Constant Integer olFormatRichText = 3
Constant Integer olFormatUnspecified = 0

// OlSaveAsType Enumeration
Constant Integer olDoc = 4
Constant Integer olHTML = 5
Constant Integer olICal = 8
Constant Integer olMHTML = 10
Constant Integer olMSG = 3
Constant Integer olMSGUnicode = 9
Constant Integer olRTF = 1
Constant Integer olTemplate = 2
Constant Integer olTXT = 0
Constant Integer olVCal = 7
Constant Integer olVCard = 6

// Item Types
Constant Integer olMailItem = 0
Constant Integer olAppointmentItem = 1
Constant Integer olContactItem = 2
Constant Integer olTaskItem = 3
Constant Integer olJournalItem = 4
Constant Integer olNoteItem = 5
Constant Integer olPostItem = 6
Constant Integer olDistributionListItem = 7

// OlMailRecipientType
Constant Integer olBCC        = 3
Constant Integer olCC         = 2
Constant Integer olOriginator = 0
Constant Integer olTo         = 1

OLEOBject oleNameSpace

end variables

on w_main.create
this.cb_newemail=create cb_newemail
this.cb_print=create cb_print
this.cb_saveas=create cb_saveas
this.cb_delete=create cb_delete
this.ddlb_folder=create ddlb_folder
this.ole_html=create ole_html
this.cb_cancel=create cb_cancel
this.cb_retrieve=create cb_retrieve
this.dw_inbox=create dw_inbox
this.Control[]={this.cb_newemail,&
this.cb_print,&
this.cb_saveas,&
this.cb_delete,&
this.ddlb_folder,&
this.ole_html,&
this.cb_cancel,&
this.cb_retrieve,&
this.dw_inbox}
end on

on w_main.destroy
destroy(this.cb_newemail)
destroy(this.cb_print)
destroy(this.cb_saveas)
destroy(this.cb_delete)
destroy(this.ddlb_folder)
destroy(this.ole_html)
destroy(this.cb_cancel)
destroy(this.cb_retrieve)
destroy(this.dw_inbox)
end on

event open;oleNameSpace = oleApplication.GetNameSpace("MAPI")

ole_html.of_Navigate("about:blank")

ddlb_folder.SelectItem(3)

end event

type cb_newemail from commandbutton within w_main
integer x = 2085
integer y = 32
integer width = 334
integer height = 100
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "New Email"
end type

event clicked;OLEObject oleMailItem
OLEObject oleRecipient
OLEObject oleSyncObjects
OLEObject oleSyncObject

Integer li_idx, li_max
String ls_FileName

SetPointer(HourGlass!)

oleMailItem = oleApplication.CreateItem(olMailItem)

oleMailItem.Subject    = "Test Email"
oleMailItem.BodyFormat = olFormatHTML
oleMailItem.HTMLBody   = "<HTML><BODY>Please enter the message text here.</BODY></HTML>"

oleRecipient = oleMailItem.Recipients.Add("somebody@email.com")
//oleRecipient.Type = olCC
oleRecipient.Resolve

//ls_FileName = "C:\Somefile.txt"
//oleMailItem.Attachments.Add(ls_FileName)

// send the email
oleMailItem.Send
//oleMailItem.Display

// synchronize Send/Receive groups
oleSyncObjects = oleNameSpace.SyncObjects
li_max = oleSyncObjects.Count
For li_idx = 1 To li_max
   oleSyncObject = oleSyncObjects.Item(li_idx)
   oleSyncObject.Start
Next

Parent.BringToTop = False

end event

type cb_print from commandbutton within w_main
integer x = 1719
integer y = 32
integer width = 334
integer height = 100
integer taborder = 50
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Print"
end type

event clicked;OLEObject oleMailItem
String ls_EntryID
Integer li_rc
Long ll_row

ll_row = dw_inbox.GetRow()
If ll_row = 0 Then Return

ls_EntryID = dw_inbox.GetItemString(ll_row, "entryid")
If IsNull(ls_EntryID) Or ls_EntryID = "" Then Return

li_rc = MessageBox("Confirm", &
               "Are you sure you want to print this item?", Question!, YesNo!)
If li_rc = 2 Then Return

SetPointer(HourGlass!)

oleMailItem = oleNameSpace.GetItemFromID(ls_EntryID)

oleMailItem.PrintOut()

end event

type cb_saveas from commandbutton within w_main
integer x = 1353
integer y = 32
integer width = 334
integer height = 100
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Save As"
end type

event clicked;OLEObject oleMailItem
String ls_EntryID, ls_pathname, ls_filename, ls_extn
Integer li_rc, li_SaveAsType
Long ll_row, ll_pos

ll_row = dw_inbox.GetRow()
If ll_row = 0 Then Return

ls_EntryID = dw_inbox.GetItemString(ll_row, "entryid")
If IsNull(ls_EntryID) Or ls_EntryID = "" Then Return

li_rc = GetFileSaveName("Save As", &
               ls_pathname, ls_filename, "txt", &
               "Text Only (*.txt),*.txt," + &
               "Outlook Message (*.msg),*.msg," + &
               "Rich Text (*.rtf),*.rtf," + &
               "HTML (*.html), *.html")
If li_rc = 0 Then Return

ll_pos = LastPos(ls_pathname, ".")
ls_extn = Mid(ls_pathname, ll_pos)
choose case Lower(ls_extn)
   case ".txt"
      li_SaveAsType = olTXT
   case ".msg"
      li_SaveAsType = olMSG
   case ".rtf"
      li_SaveAsType = olRTF
   case ".html"
      li_SaveAsType = olHTML
end choose

SetPointer(HourGlass!)

oleMailItem = oleNameSpace.GetItemFromID(ls_EntryID)

oleMailItem.SaveAs(ls_pathname, li_SaveAsType)

end event

type cb_delete from commandbutton within w_main
integer x = 987
integer y = 32
integer width = 334
integer height = 100
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Delete Item"
end type

event clicked;OLEObject oleMailItem
String ls_EntryID
Integer li_rc
Long ll_row

ll_row = dw_inbox.GetRow()
If ll_row = 0 Then Return

ls_EntryID = dw_inbox.GetItemString(ll_row, "entryid")
If IsNull(ls_EntryID) Or ls_EntryID = "" Then Return

li_rc = MessageBox("Confirm", &
               "Are you sure you want to delete this item?", Question!, YesNo!)
If li_rc = 2 Then Return

SetPointer(HourGlass!)

oleMailItem = oleNameSpace.GetItemFromID(ls_EntryID)

oleMailItem.Delete()

cb_retrieve.Event Clicked()

end event

type ddlb_folder from dropdownlistbox within w_main
integer x = 475
integer y = 40
integer width = 443
integer height = 688
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean sorted = false
boolean vscrollbar = true
string item[] = {"Deleted Items","Drafts","Inbox","Sent Items"}
borderstyle borderstyle = stylelowered!
end type

type ole_html from u_web_browser within w_main
integer x = 37
integer y = 960
integer width = 2747
integer height = 1604
integer taborder = 90
string binarykey = "w_main.win"
end type

type cb_cancel from commandbutton within w_main
integer x = 2450
integer y = 32
integer width = 334
integer height = 100
integer taborder = 70
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Cancel"
boolean cancel = true
end type

event clicked;Close(Parent)

end event

type cb_retrieve from commandbutton within w_main
integer x = 37
integer y = 32
integer width = 370
integer height = 100
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Retrieve -->"
end type

event clicked;Constant Integer olMail = 43
OLEObject oleInbox, oleItems, oleMailItem
Integer li_folder, li_count, li_item
String ls_folder
Long ll_next

SetPointer(HourGlass!)

ls_folder = ddlb_folder.Text
choose case ls_folder
   case "Deleted Items"
      li_folder = olFolderDeletedItems
   case "Drafts"
      li_folder = olFolderDrafts
   case "Inbox"
      li_folder = olFolderInbox
   case "Sent Items"
      li_folder = olFolderSentMail
   case else
      li_folder = olFolderInbox
end choose

dw_inbox.SetRedraw(False)

dw_inbox.Reset()

oleInbox = oleNameSpace.GetDefaultFolder(li_folder)

oleItems = oleInbox.Items

li_count = oleItems.Count

// sort most recent first
oleItems.Sort("ReceivedTime", True)

For li_item = 1 To li_count
   oleMailItem = oleItems.Item(li_item)
   If oleMailItem.Class = olMail Then
      ll_next = dw_inbox.InsertRow(0)
      dw_inbox.SetItem(ll_next, "sendername", oleMailItem.SenderName)
      dw_inbox.SetItem(ll_next, "subject", oleMailItem.Subject)
      dw_inbox.SetItem(ll_next, "receivedtime", oleMailItem.ReceivedTime)
      dw_inbox.SetItem(ll_next, "entryid", oleMailItem.EntryID)
   End If
   If ll_next > 24 Then Exit  // limit to first 25 items
Next

dw_inbox.Sort()
dw_inbox.SetRedraw(True)
dw_inbox.Event RowFocusChanged(dw_inbox.GetRow())
dw_inbox.SetFocus()

end event

type dw_inbox from datawindow within w_main
integer x = 37
integer y = 168
integer width = 2747
integer height = 764
integer taborder = 80
string title = "none"
string dataobject = "d_inbox"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event rowfocuschanged;OLEObject oleMailItem
String ls_EntryID

ole_html.of_SetSource("")

If currentrow = 0 Then Return

this.SelectRow(0, False)
this.SelectRow(currentrow, True)

ls_EntryID = this.GetItemString(currentrow, "entryid")
If IsNull(ls_EntryID) Or ls_EntryID = "" Then Return

oleMailItem = oleNameSpace.GetItemFromID(ls_EntryID)

choose case oleMailItem.BodyFormat
   case olFormatHTML
      ole_html.of_SetSource(oleMailItem.HTMLBody)
   case olFormatPlain
      ole_html.of_SetSource(oleMailItem.Body)
   case else
      ole_html.of_SetSource(oleMailItem.Body)
end choose

end event


Start of PowerBuilder Binary Data Section : Do NOT Edit
07w_main.bin 2564 1675303494
2000000a00e011cfd0e11ab1a1000000000000000000000000000000000003003e0009fffe000000060000000000000000000000010000000100000000000010000000000200000001fffffffe0000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffffefffffffefffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff006f00520074006f004500200074006e00790072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050016ffffffffffffffff0000000100000000000000000000000000000000000000000000000000000000be35aff001d936aa00000003000001800000000000500003004f0042005800430054005300450052004d0041000000000000000000000000000000000000000000000000000000000000000000000000000000000102001affffffff00000002ffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000009c00000000004200500043004f00530058004f00540041005200450047000000000000000000000000000000000000000000000000000000000000000000000000000000000001001affffffffffffffff000000038856f96111d0340ac0006ba9a205d74f00000000be35aff001d936aabe35aff001d936aa000000000000000000000000004f00430054004e004e00450053005400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001020012ffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000030000009c000000000000000100000002fffffffe0000000400000005fffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
20ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000004c00003e1d000029720000000000000000000000000000000000000000000000000000004c0000000000000000000000010057d0e011cf3573000869ae62122e2b00000008000000000000004c0002140100000000000000c0460000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c00003e1d000029720000000000000000000000000000000000000000000000000000004c0000000000000000000000010057d0e011cf3573000869ae62122e2b00000008000000000000004c0002140100000000000000c0460000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
17w_main.bin 2564 1675303494
End of PowerBuilder Binary Data Section : No Source Expected After This Point