TestSmtp

TestSmtp

Postby Rick Lipkin » Tue Jul 08, 2008 7:15 pm

To All

I have some code which derives its syntax from the TestSmtp example. I am using a Dialog box at the begining of my program before the main MDI window to determine if a User exists in the permissions table.

I give the user the option to add themselves to the table and upon successful addition to the table .. I want to send an SMTP e-mail to the application admin.

When I fire off this code and i get to the e-mail .. I get an alert that:

"You must create a Main window in order to use a Tsocket Object"


That is all well and fine .. but i am using the new Transparent clause and Transparent only seems to work for dialogs NOT windows.

Any Ideas here .. will the transparent clause work from a window and a redefine dialog from resources ?? It seems the transparent clause only works from code ?? In any rate, the SMTP mail is my most urgent problem.

Sorry for the attached code .. I have tried to condense it.

Rick Lipkin
SC Dept of Health, USA



//-------------------------------
IF xLOGIN = "UNKNOWN"

yLOGIN := WNetGetUser() // FiveWin function
yLOGIN := UPPER( yLOGIN )

oSAY := NIL
cSAY := NIL

cWELCOME := "WELCOME to the PMO Strategic Projects Vital Signs"
cSAY := "The System could not resolve your UserID "
cSAY1 := yLOGIN
cSAY2 := "You now have a choice to Add yourself as a"
cSAY3 := "Project Manager or enter the program Read Only?"

nOK := 0

DEFINE BRUSH oBru FILENAME ( cDEFA+"\PMO.BMP" )

DEFINE DIALOG oDLG1 ;
TITLE "WELCOME" ;
SIZE 700, 400 BRUSH oBRU TRANSPARENT

@ 0, 2 SAY cWELCOME OF oDlg1 COLOR "W+/W"
oDlg1:aControls[ 1 ]:lTransparent = .t.
@ 1, 2 SAY cSAY OF oDlg1 COLOR "W+/W"
oDlg1:aControls[ 2 ]:lTransparent = .t.
@ 1.5,2 SAY cSAY1 OF oDlg1 COLOR "W+/W"
oDlg1:aControls[ 3 ]:lTransparent = .t.
@ 2,2 SAY cSAY2 OF oDlg1 COLOR "W+/W"
oDlg1:aControls[ 4 ]:lTransparent = .t.
@ 2.5,2 SAY cSAY3 OF oDlg1 COLOR "W+/W"
oDlg1:aControls[ 5 ]:lTransparent = .t.

@ 50, 10 BTNBMP oBtn1 RESOURCE "YES" ;
SIZE 145, 15 OF oDlg1 ;
ACTION( oDlg1:End(), nOK := 1 )
oBtn1:lTransparent := .T.

@ 70, 10 BTNBMP oBtn2 RESOURCE "PMGR" ;
SIZE 145, 15 OF oDlg1;
ACTION( IF( _Addum( oDlg1 ),nOK := 4 , nOK := 2 ))
oBtn2:lTransparent := .T.

@ 90, 10 BTNBMP oBtn3 RESOURCE "CANCEL" ;
SIZE 145, 15 OF oDlg1 ;
ACTION( oDlg1:END(), nOK := 3)
oBtn3:lTransparent := .T.

ACTIVATE DIALOG oDlg1 CENTERED

DO CASE
CASE nOK = 1
xLOGIN := WNetGetUser() // FiveWin function
xLOGIN := UPPER( xLOGIN )
xLOGIN := xLOGIN+SPACE(8)
xLOGIN := SUBSTR(xLOGIN,1,8)

xREAD := 'Y'
xWRITE := 'N'
xPROJ := 'N'
xSUPER := 'N'

CASE nOK = 2
CLOSE DATABASES
RETURN(.F.)

CASE nOK = 4
// do nothing and proceed //

OTHERWISE
oDLG1:END()
CLOSE DATABASES
RETURN(.F.)
ENDCASE

ENDIF

// main mdi

...
...

//--------------------------
Static Func _AddUM( oDLG1 )

LOCAL oRsUser, cSQL, oERR, SAYING, oRsOwn
LOCAL cHOST, cUSEREID, cPMNAME, cPMEMAIL, cPMONAME, cPMOEMAIL
LOCAL oOutMail, cIP, cFROM, cTO, cSUBJECT, cMESSAGE

xLOGIN := WNetGetUser() // FiveWin function
xLOGIN := UPPER( xLOGIN )
xLOGIN := xLOGIN+SPACE(8)
xLOGIN := SUBSTR(xLOGIN,1,8)

SAYING := "WELCOME to the NEW Project Manager Add Routine"+chr(10)

IF MsgYesNo( saying )
ELSE
oDlg1:End()
RETURN(.F.)
ENDIF

// userview add routine

oRsuser := TOleAuto():New( "ADODB.Recordset" )
oRsuser:CursorType := 1 // opendkeyset
oRsuser:CursorLocation := 3 // local cache
oRsuser:LockType := 3 // lockoportunistic

cSQL := "SELECT * FROM USERINFO order by USERID"

TRY
oRsuser:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
MsgInfo( "Error in Opening USERINFO table" )
oDlg1:End()
RETURN(.F.)
END TRY


xREAD := 'Y'
xWRITE := 'N'
xPROJ := 'N'
xSUPER := 'N'

// double check for no dupes //

oRsuser:Find("USERID = '"+xLOGIN+"'" )
IF .not. oRsuser:eof
oRsUser:CLose()
SAYING := "SORRY ... "+xLOGIN+" already Exists in the User Table .. Aborting"
MsgInfo( saying )
oDlg1:End()
RETURN(.F.)
ENDIF

IF _UserView( "A", oRsUser, "login" )

xREAD := "Y"
xWRITE := oRsUser:Fields("write"):Value
xPROJ := oRsUser:Fields("mgr"):Value
xSUPER := oRsUser:Fields("super"):Value
xLOGIN := oRsUser:Fields("userid"):Value

cPMNAME := alltrim(oRsUser:Fields("name"):Value)
cPMEMAIL := alltrim(oRsUser:Fields("userid"):Value)+"@"+alltrim(oRsUser:Fields("domain"):Value)

// send mail from here

oRsOwn := TOleAuto():New( "ADODB.Recordset" )
oRsOwn:CursorType := 1 // opendkeyset
oRsOwn:CursorLocation := 3 // local cache
oRsOwn:LockType := 3 // lockoportunistic

cSQL := "SELECT * FROM OWNER"

TRY
oRSOwn:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
MsgInfo( "ERROR Opening Table OWNER to get E-mail parameters" )
oRsUser:CLose()
oDLG1:End()
RETURN(.T.)
END TRY

IF oRsOwn:eof
MsgInfo( "Sorry .. No Records for Table OWNER for E-mail" )
oRsUser:CLose()
oRsOwn:Close()
oDLG1:End()
RETURN(.T.)
ENDIF

cHOST := alltrim(oRsOwn:Fields("smtp_host"):Value)
cUSEREID := oRsOwn:Fields("usereid"):Value // get the pmo admin

oRsUser:MoveFirst()
oRsUser:Find("usereid = '"+cUSEREID+"'")

IF oRsUser:eof
cPMONAME := alltrim(oRsOwn:Fields("userid"):Value)+"@"+alltrim(oRsOwn:Fields("domain"):Value)
cPMOEMAIL := alltrim(oRsOwn:Fields("userid"):Value)+"@"+alltrim(oRsOwn:Fields("domain"):Value)
ELSE
cPMONAME := ALLTRIM(oRsUser:Fields("name"):Value)
cPMOEMAIL := alltrim(oRsUser:Fields("userid"):Value)+"@"+alltrim(oRsUser:Fields("domain"):Value)
ENDIF

oRsOwn:CLose()
oRsUser:CLose()

cFROM := "PMO Admin"
cTO := "LIPKINRM@DHEC.SC.GOV"

cSUBJECT := "Welcome New Project Manager"
cMESSAGE := "Test"

WSAStartup()
oOutMail := TSmtp():New( cIP := GetHostByName( cHOST ) )

* MsgInfo( cIP )
* oOutMail:bConnecting = { || MsgInfo( "Connecting to "+cHOST ) }
* oOutMail:bConnected = { || MsgInfo( "Connected" ) }
* oOutMail:bDone = { || MsgInfo( "Message sent successfully" ) }

oOutMail:SendMail( cFROM,; // From
{ cTO },; // To
cMESSAGE,; // message
cSUBJECT, ) // subject


oDLG1:End()
ELSE
oRsUser:CLose()
oDlg1:End()
RETURN(.F.)
ENDIF

RETURN(.T.)
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby Rick Lipkin » Tue Jul 08, 2008 8:49 pm

To All

As seems to be the case .. the longer you look at a problem .. the solution seems to be at hand.

YES .. it seems you do have to have defined a Window for Tsocket to work ..

Since the dialog routine fires before the main Window MDI .. it was a simple matter of setting a logical variable which I evaluate with the On Init clause when I open the MDI ..

Problem solved.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby James Bott » Tue Jul 08, 2008 9:35 pm

Rick,

Another way you might do it, is to create a main window then hide it. After the email is sent you can then show the main window. I think you would also have to define coordinates for the window that were offscreen (negative nTop, nLeft) before hiding it, otherwise it might be visible for an instant before hiding. Then when showing it you can maximize it, then show it.

Your solution is simpler.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Rick Lipkin » Tue Jul 08, 2008 11:11 pm

James

I thought about that and even tried it ( kinda sorta ). I actually created a window but the problem is that the whole module became non-modal and by the time the e-mail was sent .. the main MDI window kicked in causing all kinds of problems.

I decided to sorta wrap the e-mail module and keep the dialog then upon completion of the dialog I set a logical .. when the MDI kicked in .. I did an in-line if() to test for the logical and send the mail ON Init.

This was the ticket !!

Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Postby nageswaragunupudi » Wed Jul 09, 2008 3:36 am

Offtopic

>
I think you would also have to define coordinates for the window that were offscreen (negative nTop, nLeft) before hiding it, otherwise it might be visible for an instant before hiding. Then when showing it you can maximize it, then show it.
>

It is now no more necessary to adopt this indirect method to activate window in hidden mode. New syntax ACTIVATE WINDOW HIDDEN activates the window without showing it even for an instant.
Regards

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

Postby James Bott » Wed Jul 09, 2008 4:22 am

NageswaraRao,

It is now no more necessary to adopt this indirect method to activate window in hidden mode. New syntax ACTIVATE WINDOW HIDDEN activates the window without showing it even for an instant.


Thanks for pointing that out--I didn't know about it.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Rick Lipkin » Wed Jul 09, 2008 1:08 pm

To All

Nice to know about the activate window hidden .. however, like I ran into you will be in a non-modal situation and your program code will continue to execute outside your window ..

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 63 guests