Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

emailing with Winsock control....

Status
Not open for further replies.

tushar149

Programmer
Oct 22, 2003
26
0
0
IN
HI

I have problem with emailing using winsock control. Actually i had written code in VB that can send email using winsock control. But when i apply same logic in vfp it's not working. Actually i am not getting any response from getdata method of vfp winsock control.. It's not getting any data from server which i had specified...can anybody please show me how to use winsock control in vfp to send mails to SMTP server..
please help it's an urgent..


Tushar

 
tushar149

Can you post the code you are using, so we can see where the problem is?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
HI

Following code i have written in Dataarrival procedure of winsockcontrol.Actually problem is winsock controls's Getdata method is not receiving any data from remote computer.And same method receives data in VB.. i have checked it by debugging the code in VB, but when i debug in vfp code i found that there is no data in getdata method. I don't know whether i have used wrong syntax in vfp or wrong parameters..Anyways i am sending vb code that i have written in dataarrival procedure...pl help..

[VFP Code....Dataarrival procedure of winsock control]
*** ActiveX Control Event ***
LPARAMETERS bytestotal
set step on
do while sendstat <= 6
data = ""
this.GetData->data
thisform.txtstatus.value = Data
do case sendstat
case sendstat = 1
this.object.SendData ("Hello Test")
case sendstat = 2
this.object.SendData("MAIL FROM:"+THISFORM.TXTFROM.VALUE)
case sendstat = 3
this.object.SendData("RCPT TO:"+THISFORM.TXTTO.VALUE)
case sendstat = 4
this.object.SendData("DATA")
this.Object.SendData("SUbject:"+thisform.txtsubject.value)
this.object.SendData(thisform.txtmessage.value)
case sendstat = 5
this.object.SendData(".")
case sendstat = 6
this.object.SendData("QUIT")
endcase
sendstat = sendstat+1
enddo




[VB code...Dataarrival procedure of winsock control]
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
Winsock1.GetData Data
txtstatus.SelLength = Len(txtstatus.Text)
txtstatus.SelText = Data

Select Case SendStat
Case 1
Winsock1.SendData "HELO TEST" & vbCrLf
Case 2
Winsock1.SendData "MAIL FROM:" & txtsender.Text & vbCrLf
Case 3
Winsock1.SendData "RCPT TO:" & txtreceive.Text & vbCrLf
Case 4
Winsock1.SendData "DATA" & vbCrLf
Winsock1.SendData "subject:" & txtsubject.Text & vbCrLf
Winsock1.SendData txtmessage.Text & vbCrLf
Case 5
Winsock1.SendData vbCrLf & "." & vbCrLf
Case 6
Winsock1.SendData "QUIT" & vbCrLf
End Select
SendStat = SendStat + 1
End Sub
 
tushar149,

You need to pass parameters into the GetData method in order to get the contents. Here is a quick example of DataArrival code:

Code:
LPARAMETERS bytestotal
#DEFINE vbString 8
lcString = ""
THIS.GetData(@lcString, vbString, bytestotal)
THISFORM.r_cReceiveString = THISFORM.r_cReceiveString + lcString

Andy
 
Hello

Thanks Andy

It has worked for the first time in the loop and when in the loop when i send particular data back to the server(as you can see from senddata method), after that in the loop again it runs get data method then it shows lcstring value empty. IN short when second time loops goes through getdata method reuturns empty value for lcString...

Here is what i have written after your valuable suggestion pl tell me what could be the problem...

*** ActiveX Control Event ***
LPARAMETERS bytestotal
set step on
do while sendstat <= 6
**data = ""
#DEFINE vbString 8
lcString = ""
THIS.GetData(@lcString, vbString, bytestotal)
thisform.txtstatus.value = lcString
do case sendstat
case sendstat = 1
this.object.SendData("HELO")
case sendstat = 2
this.object.SendData("MAIL FROM:"+THISFORM.TXTFROM.VALUE)
case sendstat = 3
this.object.SendData("RCPT TO:"+THISFORM.TXTTO.VALUE)
case sendstat = 4
this.object.SendData("DATA")
this.Object.SendData("SUbject:"+thisform.txtsubject.value)
this.object.SendData(thisform.txtmessage.value)
case sendstat = 5
this.object.SendData(".")
case sendstat = 6
this.object.SendData("QUIT")
endcase
sendstat = sendstat+1
enddo
 
tushar149,

I'm not sure why you're expecting to get data in the 2nd GetData call in your loop. The DataArrival event is fired when there is data ready to be retrieved. When you perform this statement:

Code:
THIS.GetData(@lcString, vbString, bytestotal)

It takes the entire contents of your receive buffer and places it into lcString. I don't quite get why you're expecting to see data there immediately the 2nd time around.

Any time you receive data you should let the DataArrival event fire and then you can fetch the contents and react to it accordingly. I wouldn't place the loop inside the DataArrival method. I would place the loop outside the method and simply let DataArrival fetch and store any incoming data. You most likely will want _VFP.Autoyield = .F. and a DOEVENTS() placed at the bottom of your loop.

Andy
 
A problem I see with the mechanism you're using is that you expect the state of the mail server to ALWAYS follow a strict pattern: State1, state2, etc. through state6.

You have it rolling around in a loop to make it look like a "Finite State Machine", but there is no logic deciding when to go to the next step, so the only thing being done by the loop is sharing the GetData method call.


This is the exact same logic (with the GetData method call replaced with a new method, called GetResponse):
(basically, I'm trying to illustrate that the Loop is superfluous in the above code. Personally, I'd recommend keeping a loop, only make it make sense: use the loop to evaluate the response from the server and advance to the proper client state based on the server's response. For code in VFP that already does this, see: ... look for the comment that notes "Control Loop" and examine how "ReadWrite" works, noting the EXIT commands when ReadWrite fails...)
Code:
LPARAMETERS bytestotal
lcResp = this.GetResponse("HELO Test")
lcResp = this.GetResponse("MAIL FROM:"+THISFORM.TXTFROM.VALUE)
lcResp = this.GetResponse("RCPT TO:"+THISFORM.TXTTO.VALUE)
lcResp = this.GetResponse("DATA")
lcResp = this.GetResponse("Subject:"+thisform.txtsubject.value)
lcResp = this.GetResponse("thisform.txtmessage.value)
lcResp = this.GetResponse(".")
lcResp = this.GetResponse("QUIT")

FUNCTION GetResponse
  LPARAMETERS tcOutText
  LOCAL lnNow
  THISFORM.r_cReceiveString = '' && Clear receive buffer
  THIS.SendData( tcOutText )
  DECLARE Sleep IN Win32Api AS apiSleep LONG dwMilliseconds
  lnNow = SECONDS()
  * Timeout waiting for response after 100 seconds:
  DO WHILE (lnNow-Seconds() < 100) ;
     and NOT CHR(13) $ THISFORM.r_cReceiveString
    apiSleep(333) && wait 1/3 second for response from server
    * I'm not sure if you should have DOEVENTS here
    * instead of the apiSleep call... it depends on
    * whether VFP allows the DataArrival event to fire
    * during the Sleep function...
  ENDDO
  RETURN THISFORM.r_cReceiveString
ENDFUNC

FUNCTION DataArrival
  LPARAMETERS bytestotal
  #DEFINE vbString 8
  lcString = ""
  THIS.GetData(@lcString, vbString, bytestotal)
  THISFORM.r_cReceiveString = THISFORM.r_cReceiveString + lcString
ENDFUNC
 
Hello Andy

Actually i have tried writting loop outside dataarrival procedure...but it gives me oledispatch error...Actually i have written that loop in sendmail button..in which i have mentioned server name & port number...can you send me some more suggestions. Actually it's an urgent requirement...can you write me exact code..please......

Tushar


 
tushar,

I think your best bet is to look at the Wiki link that WGCS posted earlier in this thread. I think it contains all the goodies you need.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top