PUBLIC ofrmmapi
ofrmmapi=NEWOBJECT("frmmapi")
ofrmmapi.Show
RETURN
DEFINE CLASS frmmapi AS form
Top = 0
Left = 0
Height = 433
Width = 686
DoCreate = .T.
BackColor = RGB(192,192,192)
Caption = "Form1"
Name = "frmMapi"
ADD OBJECT shape1 AS shape WITH ;
BackStyle = 0, ;
Curvature = 20, ;
Height = 265, ;
Left = 12, ;
Top = 9, ;
Width = 325, ;
Name = "Shape1"
ADD OBJECT shape2 AS shape WITH ;
BackStyle = 0, ;
Curvature = 20, ;
Height = 265, ;
Left = 348, ;
Top = 9, ;
Width = 325, ;
Name = "Shape2"
ADD OBJECT olemessage AS olecontrol WITH ;
Top = 0, ;
Left = 612, ;
Height = 100, ;
Width = 100, ;
TabIndex = 14, ;
AddressResolveUI = .T., ;
Name = "oleMessage",;
OleClass = "MSMAPI.MAPIMessages.1"
ADD OBJECT olesession AS olecontrol WITH ;
Top = 0, ;
Left = 552, ;
Height = 100, ;
Width = 100, ;
TabIndex = 13, ;
DownloadMail = .F., ;
Name = "oleSession",;
OleClass = "MSMAPI.MAPISession.1"
ADD OBJECT cmdsend AS commandbutton WITH ;
Top = 336, ;
Left = 588, ;
Height = 29, ;
Width = 94, ;
Caption = "Send", ;
TabIndex = 11, ;
Name = "cmdSend"
ADD OBJECT lstfilename AS listbox WITH ;
RowSourceType = 7, ;
Height = 205, ;
Left = 360, ;
TabIndex = 8, ;
Top = 45, ;
Width = 300, ;
Name = "lstFilename"
ADD OBJECT cmdclose AS commandbutton WITH ;
Top = 384, ;
Left = 588, ;
Height = 29, ;
Width = 94, ;
Caption = "Close", ;
TabIndex = 12, ;
Name = "cmdClose"
ADD OBJECT txtrecipient AS textbox WITH ;
ControlSource = "", ;
Format = "K", ;
Height = 25, ;
Left = 24, ;
TabIndex = 2, ;
Top = 40, ;
Width = 301, ;
Name = "txtRecipient"
ADD OBJECT lstrecipients AS listbox WITH ;
Height = 157, ;
Left = 24, ;
Sorted = .T., ;
TabIndex = 10, ;
Top = 93, ;
Width = 301, ;
Name = "lstRecipients"
ADD OBJECT label1 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "List of Recipients:", ;
Height = 18, ;
Left = 24, ;
Top = 71, ;
Width = 112, ;
TabIndex = 9, ;
Name = "Label1"
ADD OBJECT label2 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Enter Recipient Name to Add:", ;
Height = 18, ;
Left = 24, ;
Top = 22, ;
Width = 187, ;
TabIndex = 1, ;
Name = "Label2"
ADD OBJECT label3 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Select Attachments:", ;
Height = 18, ;
Left = 360, ;
Top = 22, ;
Width = 126, ;
TabIndex = 7, ;
Name = "Label3"
ADD OBJECT edtnotetext AS editbox WITH ;
Height = 73, ;
Left = 12, ;
TabIndex = 6, ;
Top = 348, ;
Width = 565, ;
ControlSource = "THISFORM.oleMessage.MsgNoteText", ;
Name = "edtNoteText"
ADD OBJECT label4 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Message Text:", ;
Height = 18, ;
Left = 12, ;
Top = 324, ;
Width = 91, ;
TabIndex = 5, ;
Name = "Label4"
ADD OBJECT txtsubject AS textbox WITH ;
ControlSource = "THISFORM.oleMessage.MsgSubject", ;
Format = "K", ;
Height = 25, ;
Left = 72, ;
TabIndex = 4, ;
Top = 284, ;
Width = 505, ;
Name = "txtSubject"
ADD OBJECT label5 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Subject:", ;
Height = 18, ;
Left = 12, ;
Top = 288, ;
Width = 52, ;
TabIndex = 3, ;
Name = "Label5"
PROCEDURE Init
WITH THISFORM
WAIT WINDOW NOWAIT "Please wait ... Logging Into Mail" NOCLEAR
* Signon to mail
.oleSession.Signon
* If the session ID is not valid, do not allow the form to load
IF .oleSession.SessionID > 0
.oleMessage.SessionID = .oleSession.SessionID
ELSE
WAIT WINDOW NOWAIT "Form Cannot Load: Login Failed"
RETURN .F.
ENDIF
* Start a new message
.oleMessage.Compose
ENDWITH
WAIT CLEAR
ENDPROC
PROCEDURE cmdsend.Click
WAIT WINDOW NOWAIT NOCLEAR "Sending Message ... "
WITH THISFORM
* Add an attachment if a file has been selected
IF !EMPTY(.lstFilename.Value)
* You must provide the complete path to the attachment
.oleMessage.AttachmentPathname = .lstFilename.List(2) + .lstFilename.Value
ENDIF
* If the subject, note text, or recipient list is empty, a Compose
* message dialog will be displayed.
IF EMPTY(.txtSubject.Value) ;
OR EMPTY(.edtNoteText.Value) ;
OR (.lstRecipients.ListCount = 0)
.oleMessage.Send(1)
ELSE
.oleMessage.Send(0)
ENDIF
* Reset all values
.txtRecipient.Value = ""
.lstRecipients.Clear
.txtSubject.Value = ""
.edtNoteText.Value = ""
* Start a new message
.oleMessage.Compose
ENDWITH
WAIT WINDOW NOWAIT "Message Sent! New Message Ready"
ENDPROC
PROCEDURE cmdclose.Click
* Sign off of mail and release the form
THISFORM.oleSession.Signoff
THISFORM.Release
ENDPROC
PROCEDURE txtrecipient.Valid
* Only add a recipient if one has been typed in (to prevent blank recipients)
IF !EMPTY(ALLTRIM(THIS.Value))
WITH THISFORM
* Increment the Recipient index
.oleMessage.RecipIndex = ;
IIF(.lstRecipients.Listcount = 0, 0, ;
.oleMessage.RecipIndex + 1)
* Set the Recipient name and resolve
.oleMessage.RecipDisplayName = ALLTRIM(THIS.value)
.oleMessage.ResolveName
* Add the name to the Listbox on the form
.lstRecipients.AddItem(THISFORM.oleMessage.RecipDisplayName)
ENDWITH
ENDIF
ENDPROC
PROCEDURE edtnotetext.Click
* Trim the contents
THIS.Value = ALLTRIM(THIS.Value)
ENDPROC
PROCEDURE txtsubject.Valid
* Trim the contents
THIS.Value = ALLTRIM(THIS.Value)
ENDPROC
ENDDEFINE