Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to send mail with VFP
Message
General information
Forum:
Visual FoxPro
Category:
Internet applications
Miscellaneous
Thread ID:
00703516
Message ID:
00703793
Views:
12
Hi,

As I was already using Winsock (basic in Win 9x and NT), I found some document about the SMTP RFC-821 protocol. So it's not too hard to connect to a configured SMTP server and send SMTP commands (it's basic ASCII commands).

For SMTP RFC-821 protocol, just check this link http://www.freesoft.org/CIE/RFC/821/index.htm

Here is a very basic code to send a simple mail :

Create a form, with 3 TextBox (TxtSrv, TxtFrom, TxtTo), an EditBox (EdtData) and a CommandButton (CmdSend). Add a property to the form (mailAct) to use as a counter.

Put a Winsock object (WS) on my form at design time.

1. In the SEND button's click, simply connect to the SMTP server
&& Connect to SMTP Server
this.parent.ws.object.remotehost=ALLTRIM(this.parent.txtSrv.text)
this.parent.ws.object.remoteport = 25
this.parent.ws.object.connect

&& Start Mail Activity at 1
thisform.mailact = 1
2. In the WS's DataArrival method, put this code
*** ActiveX Control Event ***
LPARAMETERS bytestotal
local lStrData as String
LOCAL CRLF

CRLF = CHR(13)+CHR(10)
lStrData=""

if this.object.state<>8
	This.object.getdata(@lStrData,8)
&&	This.parent.Edit1.value = This.parent.Edit1.value + lStrData + CRLF
	DO CASE 
		CASE LEFT(lStrData,3) = "250" .OR.;
			 LEFT(lStrData,3) = "220" .OR.;
			 LEFT(lStrData,3) = "354" .OR.;
			 LEFT(lStrData,3) = "221"
			DO CASE
				CASE thisform.MailAct = 1
					this.sendData("HELO "+ALLTRIM(this.parent.txtSrv.text)+CRLF)
					thisform.MailAct = thisform.MailAct + 1
				CASE thisform.MailAct = 2
					this.sendData("MAIL FROM:<"+ALLTRIM(this.parent.txtFrom.text)+">"+CRLF)
					thisform.MailAct = thisform.MailAct + 1
				CASE thisform.MailAct = 3
					this.sendData("RCPT TO:<"+ALLTRIM(this.parent.txtTo.text)+">"+CRLF)
					thisform.MailAct = thisform.MailAct + 1
				CASE thisform.MailAct = 4
					this.sendData("DATA"+CRLF)
					thisform.MailAct = thisform.MailAct + 1
				CASE thisform.MailAct = 5
					this.sendData(ALLTRIM(this.parent.EdtData.text)+CRLF+"."+CRLF)
					thisform.MailAct = thisform.MailAct + 1
				CASE thisform.MailAct = 6
					this.sendData("QUIT"+CRLF)
					thisform.MailAct = thisform.MailAct + 1
				CASE thisform.MailAct = 7
					this.object.Disconnect
			ENDCASE	
		OTHERWISE 
			MESSAGEBOX("Error sending mail ("+LEFT(lStrData,3)+")"+CRLF+lStrData)
	ENDCASE
endif
So it's not complete, just check if textboxes are completed, mail adress are valid (If not valid, SMTP server return an no-fatal error).

I hope this will help.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform