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!

How to make SMTP commands to work from VFP

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I have looked in the Internet about the SMTP commands. My question: How to make them work within VFP? I'll give one dollar premium for the one who gives the correct answer.
 
Note : to send an e-mail using SMTP (This requires the SMTP/POP3 Email Engine for Visual FoxPro (SEE4FP) Dynamic Link library)

Code:
     #INCLUDE KEYCODE.FOX
     #INCLUDE SEE32CON.FOX
   
     DECLARE INTEGER seeAttach in SEE32.DLL INTEGER NbrChans, INTEGER KeyCode
     DECLARE INTEGER seeClose in SEE32.DLL INTEGER Chan
     DECLARE INTEGER seeErrorText in SEE32.DLL INTEGER Chan, INTEGER Code, STRING
                     @Buffer,INTEGER BufLen
     DECLARE INTEGER seeIntegerParam in SEE32.DLL INTEGER Chan, INTEGER Param,
                     INTEGER Value
     DECLARE INTEGER seeRelease in SEE32.DLL
     DECLARE INTEGER seeStringParam in SEE32.DLL INTEGER Chan, INTEGER Param,
                     STRING @Value
   
     *** PROGRAMMER: Edit these strings [use host name or IP address for server] ***
     SmtpServer = "10.0.0.1"
     SmtpFrom = &quot;<mike@10.0.0.1>&quot;
     SmtpReply = Chr(0)
     SmtpTo   = &quot;<mike@10.0.0.1>&quot;
     DiagFile = &quot;HELLO.LOG&quot;
     *** END PROGRAMMER ***
   
   ? &quot;HELLO 3/27/2002&quot;
     Code = seeAttach(1, SEE_KEY_CODE)
     if Code < 0
       ? &quot;Cannot attach SEE&quot;
       return
     endif
     Code = seeStringParam(0, SEE_LOG_FILE, @DiagFile)
     *** set maximum connect wait to 10 seconds
     Code = seeIntegerParam(0, SEE_CONNECT_WAIT, 10000)
     *** connect to POP3 server
   ? &quot;Connecting to &quot; + SmtpServer
     Code = seeSmtpConnect(0, @SmtpServer, @SmtpFrom, @SmtpReply)
     if Code < 0
       Temp = SPACE(128)
       Code = seeErrorText(0,Code,@Temp,128)
       ? Left(Temp,Code)
     else
       *** send email message
       ? &quot;Sending email to &quot; + SmtpTo
       Code = seeSendEmail(0,SmtpTo,&quot;&quot;,&quot;&quot;,&quot;This is the subject&quot;,&quot;Message&quot;,&quot;&quot;)
       if Code < 0
         Temp = SPACE(128)
         Code = seeErrorText(0,Code,@Temp,128)
         ? Left(Temp,Code)
       else
         ? &quot;Email has been sent.&quot;
       endif
     endif
   ? &quot;Done.&quot;
     Code = seeClose(0)
     Code = seeRelease()
     return
 
Rick Strahl ( also has a DLL (wwIPStuff.dll) that permits you to send e-mail via SMTP with this code:
Code:
SET CLASSLIB TO wwIPSTUFF ADDITIVE

SET PROCEDURE TO wwUtils ADDITIVE

 

loIP = CREATEOBJECT(&quot;wwIPStuff&quot;)

 

loIP.cMailServer = &quot;your.mailserver.com&quot;  && or IP address

loIP.cSenderEmail = &quot;yourname@yours.com&quot;

loIP.cSenderName = &quot;Jimmy Roe &quot;

 

loIP.cRecipient = &quot;jroe@roe.com &quot;

loIP.cCCList = &quot;jbox@com.com,ttemp@temp.com&quot;

loIP.cBCCList = &quot;somebody@nowhere.com&quot;

 

loIP.cSubject = &quot;wwIPStuff Test Message&quot;

loIP.cMessage = &quot;Test Message body&quot; + CHR(13)

 

*loIP.cAttachment = &quot;c:\temp\pkzip.exe&quot;

 

*** Wait for completion 

llResult = loIP.SendMail()       

IF !llResult

   WAIT WINDOW loIP.cErrorMsg

ELSE

   WAIT WINDOW NOWAIT &quot;Message sent...&quot;

ENDIF
 
Here is a Function that uses the MSWinsock.Winsock.1 Object. NO OUTSIDE DLL IS REQUIRED. How bout that, Gents? But, you can only send a simple text message. I build the body text string with CrLf's between lines. Or I do a FiletoStr() from a text log file and pass it into the Function. Our email server will not send emails outside the domain, so beware, there are limitations. You may also need to tweek the function to responed to your SMTP server. The Function will tell you where the failures are.

If you like this method and need better copy of the code example, post your email and I'll send a better copy.

*Function used in Program Sample
cMSGerror = &quot;&quot;
If Not SendEmail(&quot;Joe@Smo.com&quot;,&quot;Fred@Smo.com&quot;,;
&quot;Test Email&quot;,&quot;This is only a test&quot;,@cMSGerror)
Wait Window &quot;Status Email Failed! Error= &quot;+cMSGerror Timeout 15
Endif

*-------------------------------------------------------------------------------
* SendEmail(cTo,cFrom,cSubject,cBody,@cErrorMsg)
* Description:
* Sends E-mail without the use of a configured E-mail Client.
*
* Environment:
*
* Parameters:
* cTo E-mail Address(s) to be sent to.
* For multiple E-mails separate with a ';'.
* Example: JDoe@acme.com;JQPublic@acme.com
* cFrom E-mail address or computer name of message originator.
* cSubject E-mail subject line to be sent
* cBody E-mail text message to be sent.
* cErrorMsg E-Mail dialog error message received from email Server
* (This is a string that must be defined outside of the
* function, initialized to &quot;&quot; and passed by &quot;Reference&quot;)
*
* Results:
* .T. or .F.
*
* Remarks:
*
*-------------------------------------------------------------------------------
Function SendEmail(cTo,cFrom,cSubject,cBody,cErrorMsg)
Local oTCPIP, cSentData, aTo, cExact
Local nDataLen,nToSend,nError,lStatus
* Get the environment &quot;Set Exact&quot; Value
cExact = Set(&quot;Exact&quot;)
Set Exact on
* Load Locals
lStatus = .T.
cReceivedData = &quot;&quot;
nError = 0
* Do all Params have data?
If Empty(cTo) or Empty(cFrom) or ;
Empty(cSubject) or Empty(cBody)
*No, One or more Params is empty
cErrorMsg = &quot;Not Enough Data Supplied Data to Send E-Mail!&quot;
Wait Window cErrorMsg Time 10
lStatus = .F.
Else
* Parse out Email Address into Array
nToSend = Occurs(&quot;;&quot;, cTo) + 1
Dimension aTo(nToSend)
nPos1 = 1
For nX = 1 to nToSend
If nToSend = 1
aTo(nX) = cTo
Else
If nX = nToSend
aTo(nX) = Substr(cTo,nPos1)
Else
nPos2 = At(&quot;;&quot;, cTo, nX)
aTo(nX) = Substr(cTo,nPos1,nPos2-nPos1)
nPos1 = nPos2+1
Endif
Endif
Endfor
For nX = 1 to nToSend
* Set On Error For Error Trap of Object Creation
On Error nError = Error()
* Create Object
oTCPIP = CreateObject(&quot;MSWinsock.Winsock.1&quot;)
* Did an Error Occur?
If nError = 0
* No Errors. Proceed!
On Error
* Connect to Mail.SomeMailServer.Com
oTCPIP.connect(&quot;mail.SomeMailServer.com&quot;,25)
Do While oTCPIP.RemoteHost = &quot;&quot;
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>......&quot;+Chr(13)+Chr(10) Timeout .2
Enddo
* Did we Connect?
If oTCPIP.SocketHandle > 0
Do While oTCPIP.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>.....&quot;+Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.BytesReceived()
* Yes, we connected. Proceed!
oTCPIP.GetData(@cReceivedData,nDataLen)
* Did we recieve the '220' from the server?
If Left(cReceivedData,3) = &quot;220&quot;
* Yes, start sending data to mail server!
oTCPIP.SendData(&quot;mail from:<&quot; + cFrom + &quot;>&quot;+Chr(13)+Chr(10))
Do While oTCPIP.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>....&quot;+Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.BytesReceived()
oTCPIP.GetData(@cReceivedData,nDataLen)
* Did the mail server accept the 'Mail From' Data?
If Left(cReceivedData,3) = &quot;250&quot;
* Yes, Proceed with Rcpt!
oTCPIP.SendData(&quot;rcpt to:<&quot; + aTo(nX) + &quot;>&quot;+Chr(13)+Chr(10))
Do While oTCPIP.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>>...&quot;+Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.BytesReceived()
oTCPIP.GetData(@cReceivedData,nDataLen)
* Did the mail server accept the 'Rcpt to' Data?
If Left(cReceivedData,3) = &quot;250&quot;
* Yes, Proceed with email body!
oTCPIP.SendData(&quot;Data&quot;+Chr(13)+Chr(10))
Do While oTCPIP.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>>>..&quot;+Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.BytesReceived()
oTCPIP.GetData(@cReceivedData,nDataLen)
* Is the email server ready for data?
If Left(cReceivedData,3) = &quot;354&quot;
* Yes, Send in data!
oTCPIP.SendData(&quot;Subject: &quot; + cSubject +Chr(13)+Chr(10) + ;
&quot;From: &quot; + cFrom +Chr(13)+Chr(10) + ;
&quot;To: &quot; + cTo +Chr(13)+Chr(10) + ;
+Chr(13)+Chr(10) + ;
cBody+Chr(13)+Chr(10) + ;
&quot;.&quot;+Chr(13)+Chr(10))
Do While oTCPIP.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>>>>.&quot;+Chr(13)+Chr(10) Timeout 2
Enddo
nDataLen = oTCPIP.BytesReceived()
oTCPIP.GetData(@cReceivedData,nDataLen)
oTCPIP.SendData(&quot;quit&quot;+Chr(13)+Chr(10))
Else
* No. We didn't get a '354' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No. We didn't get a '250' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No. We didn't get a '250' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No. We didn't get a '220' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No, connection failed.
cErrorMsg = &quot;Failed to Connect to E-Mail Server<Mail.SomeMailServer.Com> on Port<25>!&quot;
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* Yes, Error Occurred. Couldn't create object.
On Error
cErrorMsg = Message()
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Release oTCPIP
Endfor
Endif
* Reset the &quot;Set Exact&quot; value
Set Exact &cExact
* Return the Status Value
Return lStatus
EndFunc
***********************************************************************************
* END SendEmail()
***********************************************************************************



Hope this has some application for you.

Have fun!

Allen &quot;Uncanny&quot; Schott
 
Where do I can find the MSWinsock.Winsock.1 Object ?
I use the VFP 6.

Tks
 
You need to add it to your controls. Form the menu,
go to Tools->Options->Controls and make sure the 'ActiveX Controls' radio button is selected. Then select the 'Microsoft Winsock Control' checkbox, then click 'Set as default'. Now when you modify a form, you can add it by selecting it after choosing 'ActiveX Controls' from the Form Controls 'View Classes' tool.

I hope this all made sense.

Dave S.

 
Dave S.

Thanks for yor help, but I couldn't do it.
I'm from Brazil and do not write an speack English very well (it's my 2a. language). Even, I could understand what you wrote, but could not apply. My full problem is:

1) I use VP6 for only 6 months. I worked with Fox 2.6 for 7 year and I'm having to update my concepts very hardly.
2) I really need to develop an application to send/receive e-mails without Outlook, just from the application.
3) I read the MGagnon's tip (using wwIPSTUFF), so I downloaded that zip file from the I became so happy to find out it, but it did not work. That's because it's a shareware. I did try many ways, but I could not send an simple e-mail.
4) This is the reason why I'm asking for where do I can find the MSWinsock.Winsock.1 object. So you wrote how to, but I did every thing you wrote and did not find it. I performed like this:

a) Created a new form by Form Designer;
b) Clicked TOOLS->OPTIONS->CONTROLS;
c) Selected the 'ActiveX Controls' radio button;
d) Selected all checkboxs, one by one, slowly, but could not find the 'Microsoft Winsock Control' one.
e) Saved as default.

What should I had forgot ? Or is there any other way ?

Best regards,
CCosta-BR ou Br.Programmer
 
Well, I see it both on my old computer with VFP 6 and the new one with VFP 6 and VFP 7, but if I recall, it's one of those optional things to load. You might find it on your VFP 6 or Visual Studio disks, or you can download it from Microsoft. I don't think you'll have much trouble finding it if you go looking. Dave Dardinger
 
Dave Dardinger,

Tks for your answer, but I'm having some trouble finding it.
I found a home page where where was a mswinsck.OCX file for download. I downloaded that and registered by running the [regsvr32.exe C:\WINDOWS\SYSTEM\Mswinsck.ocx] command. This command was successfully done.
Then, I :

a) Created a new form by Form Designer;
b) Clicked TOOLS->OPTIONS->CONTROLS;
c) Selected the 'ActiveX Controls' radio button;
d) Selected the 'Microsoft Winsock Control' checkbox;
e) Saved as default.

Every thing was going well. So I added it by selecting it after choosing 'ActiveX Controls' from the Form Controls 'View Classes' tool.
But suddenly, the VFP6 showed an error message, as follows:

&quot;OLE error code 0x80040112: Appropriate license for this class not found&quot;

Searching some reference about this error, I found [] where I could read:

...

Verify that the following files are in the Windows\System directory:
mfc30.dll olepro32.dll msvcrt20.dll
mfc40.dll msvcrt40.dll

If one of the following files is missing, you may receive the following error Message [OLE Error Code 0x80040112: Appropriate license for this class not found.]:


...


But all of these 5 files are in the Windows\System directory.



Is there any chance for me ? Should I use this WinSock some day ?
Some body can help me ?

Thanks.
 
Try using the following .REG file. Note: There are just four line including the second line (the blank one). If you get wordwrap on the third line in this message, undo it.

REGEDIT4

[HKEY_CLASSES_ROOT\Licenses\DB4C0D00-400B-101B-A3C9-08002B2F49FB]
@=&quot;mgkgtgnnmnmninigthkgogggvmkhinjggnvm&quot;

Rick
 
If you have registed the .OCX, then you could be able to execute this line in the command window:

oTCPIP = CreateObject(&quot;MSWinsock.Winsock.1&quot;)

If you don't get an error, then everything is ready to go.

You don't need a form with the active x control! Hello, boys, let's get out of the dark ages. You can access the Winsock object in a simple program.

If you are running on a windows platform OS you should be fine. A newer version of windows is better. You may want to reinstall Foxpro and or the Visual studio and install all the extra librarys to make thing easier. If you move the application to different computers you will have to move the mswinsck.OCX to the new computers. It should be in the C:\Windows\System directory or C:\WinNT\System32 directory. Just write a batch file to copy the file off a floppy and Register it in the registry. Easy stuff.

I was hoping this would have been an easy function to use. Is has so much potential. A simple way to send simple emails without Outlook.

Hope you can fix everything.

Good Luck.

Allen &quot;Uncanny&quot; Schott
 
Friends,

I don't know what's happening ! Nothing works !

I could not understand RGBEAN's message. Do I have to create a .REG file and then execute it ? If so, I did it, the Windows95 returned the message &quot;INFORMATION HAS BEEN SUCCESSFULLY ENTERED INTO THE REGISTRY&quot;, I re-started the systems, called VFP6, wrote the command oTCPIP = CreateObject(&quot;MSWinsock.Winsock.1&quot;), but NOTHING WORKED !
The message [OLE Error Code 0x80040112: Appropriate license for this class not found.] still remains.

While this, I could successfully use the SEE4FP routine, where I could send e-mails, download POP3 messages and so on, as I wanted. Should I forget WinSock for all ever ?
The only problem with the SEE4FP routine is that's a shareware one. So, every time it shows a pricing message. It's so bad for may commercial application. To solve it I'll have to pay U$ 100,00.


If there's still any way for me, some body please, just let me know.
 
ccostarb

Rick Strahl's wwIPStuff.vcx is free, have you tried it?
(see my reply above)
 
Hi all,

Sorry I opened Pandora's Box with the &quot;CreateObject(&quot;MSWinsock.Winsock.1&quot;)&quot;. I discovered that I had the same &quot;Class is not licensed&quot; error. on a freshly installed production machine.

That Winsock ActiveX control is not distributable. If you installed your Foxpro or Visual Studio with all the extra libaries, you should be good to go on the local machine. If you want to move it, forget it.

My bad. Sorry.

I'm looking into a way around it with out the registry key or a third party product. Maybe call the winsock DLL or create a class with the Form Winsock ActiveX control on it. That control IS distributable. We'll get this licked.

&quot;A Hilton&quot; also has a lot of insight into Foxpro and Winsock development. He has a forum called &quot;Foxsocks-developers&quot;.

Good Luck.

Allen &quot;Uncanny&quot; Schott

 
Spend th $100 on SEE4FP it works like nothing else. I use it in sending out about 1,000 e-mails a day. (Not Spam part of the business I'm in). It works easy, will take you about 10 minutes to get it running. There are some good Win32 routines, taht will allow you to read incoming e-mail from outlooks or outlook Express for receiving e-mails. This is a proven methos, that has a small learning curb. I hate spending days going through something that does not work, or you have to stress out. SEE4FP well, you can even attach files or anything else you want. Spend the $100 and you will be glad you did.
 
Hi All,

OK, NWmedia and I figured out the work around with the winsock object and the user license issue. But, you will have to copy the MSWINSCK.OCX to the Windows\System or WinNT\System32 directory and the register it with the REGSRV32 on machines that don't have development software installed. That done, you can now inherit the properties of the winsock class in your executables. If you don't understand, don't worry about it. It makes my head hurt, too. Ok Here Goes:

First you have to create a class. For those who don't know how, Here's the step-by-step.

1.Select-<File> <New> and check the <Class> button.
2.The &quot;CLASS&quot; dialog window should be up.
3.Now let's fill in the <CLASS NAME> with WINSOCK.
4.In the <BASED ON> drop down select &quot;OleControl&quot;.
5.Now fill in the <STORE IN>. Let's call it &quot;C:\TESTCODE\CLASSLIB&quot;.
6.The &quot;INSERT OBJECT&quot; dialog window should be up. Under the &quot;CHOOSE&quot; selection, select &quot;INSERT CONTROL&quot;.
7.Under the &quot;CONTROL TYPE&quot; select &quot;MICROSOFT WINSOCK CONTROL, VERSION 6.0&quot; and click <OK>.
8.Go ahead and close the &quot;CLASS DESIGNER&quot;.

That's all for the Class. Now here is the revised sample program and SENDEMAIL() function. You will have to change the &quot;mail.YourSMTPserver.com&quot; in the function to your Email server.

*-------------------------------------------------------------------------------
* SendEmail Sample program
*-------------------------------------------------------------------------------
Set ClassLib to C:\TESTCODE\CLASSLIB.VCX

cEmailTo=&quot;JoeBlow@YourSMTPserver.com&quot;
cEmailFrom=&quot;JoeBlow@YourSMTPserver.com&quot;
cEmailSubject=&quot;TEST EMAIL&quot;
cEmailBody = &quot;This is only a TEST&quot;
cEmailError = &quot;&quot;
If Not SendEmail(cEmailTo,cEmailFrom,cEmailSubject,cEmailBody,cEmailError)
Wait Window &quot;Status Email Failed! Error= &quot;+cEmailError Timeout 15
Endif


*-------------------------------------------------------------------------------
* SendEmail(cTo,cFrom,cSubject,cBody,@cErrorMsg)
* Description:
* Sends E-mail without the use of a configured E-mail Client.
*
* Environment:
*
* Parameters:
* cTo E-mail Address(s) to be sent to.
* For multiple E-mails separate with a ';'.
* Example: JDoe@acme.com;JQPublic@acme.com
* cFrom E-mail address or computer name of message originator.
* cSubject E-mail subject line to be sent
* cBody E-mail text message to be sent.
* cErrorMsg E-Mail dialog error message received from email Server
* (This is a string that must be defined outside of the
* function, initialized to &quot;&quot; and passed by &quot;Reference&quot;)
*
* Results:
* .T. or .F.
*
* Remarks:
*
*-------------------------------------------------------------------------------
Function SendEmail(cTo,cFrom,cSubject,cBody,cErrorMsg)
Local oTCPIP, cSentData, aTo, cExact
Local nDataLen,nToSend,nError,lStatus
* Get the environment &quot;Set Exact&quot; Value
cExact = Set(&quot;Exact&quot;)
Set Exact on
* Load Locals
lStatus = .T.
cReceivedData = &quot;&quot;
nError = 0
* Do all Params have data?
If Empty(cTo) or Empty(cFrom) or ;
Empty(cSubject) or Empty(cBody)
*No, One or more Params is empty
cErrorMsg = &quot;Not Enough Data Supplied Data to Send E-Mail!&quot;
Wait Window cErrorMsg Time 10
lStatus = .F.
Else
* Parse out Email Address into Array
nToSend = Occurs(&quot;;&quot;, cTo) + 1
Dimension aTo(nToSend)
nPos1 = 1
For nX = 1 to nToSend
If nToSend = 1
aTo(nX) = cTo
Else
If nX = nToSend
aTo(nX) = Substr(cTo,nPos1)
Else
nPos2 = At(&quot;;&quot;, cTo, nX)
aTo(nX) = Substr(cTo,nPos1,nPos2-nPos1)
nPos1 = nPos2+1
Endif
Endif
Endfor
For nX = 1 to nToSend
* Set On Error For Error Trap of Object Creation
On Error nError = Error()
* Create Object
oTCPIP = CREATEOBJECT(&quot;form&quot;)
oTCPIP.NewObject(&quot;oleWinsock&quot;,&quot;Winsock&quot;)
* Did an Error Occur?
If nError = 0
* No Errors. Proceed!
On Error
* Connect to Mail.YourSMTPserver.Com
oTCPIP.oleWinsock.object.connect(&quot;mail.YourSMTPserver.com&quot;,25)
Do While oTCPIP.oleWinsock.object.RemoteHost = &quot;&quot;
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>......&quot;+;
Chr(13)+Chr(10) Timeout .2
Enddo
* Did we Connect?
If oTCPIP.oleWinsock.object.SocketHandle > 0
Do While oTCPIP.oleWinsock.object.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>.....&quot;+;
Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.oleWinsock.object.BytesReceived()
* Yes, we connected. Proceed!
oTCPIP.oleWinsock.object.GetData(@cReceivedData,nDataLen)
* Did we recieve the '220' from the server?
If Left(cReceivedData,3) = &quot;220&quot;
* Yes, start sending data to mail server!
oTCPIP.oleWinsock.object.SendData(&quot;mail from:<&quot; + cFrom + &quot;>&quot;+;
Chr(13)+Chr(10))
Do While oTCPIP.oleWinsock.object.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>....&quot;+;
Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.oleWinsock.object.BytesReceived()
oTCPIP.oleWinsock.object.GetData(@cReceivedData,nDataLen)
* Did the mail server accept the 'Mail From' Data?
If Left(cReceivedData,3) = &quot;250&quot;
* Yes, Proceed with Rcpt!
oTCPIP.oleWinsock.object.SendData(&quot;rcpt to:<&quot; + aTo(nX) + &quot;>&quot;+;
Chr(13)+Chr(10))
Do While oTCPIP.oleWinsock.object.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>>...&quot;+;
Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.oleWinsock.object.BytesReceived()
oTCPIP.oleWinsock.object.GetData(@cReceivedData,nDataLen)
* Did the mail server accept the 'Rcpt to' Data?
If Left(cReceivedData,3) = &quot;250&quot;
* Yes, Proceed with email body!
oTCPIP.oleWinsock.object.SendData(&quot;Data&quot;+Chr(13)+Chr(10))
Do While oTCPIP.oleWinsock.object.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>>>..&quot;+;
Chr(13)+Chr(10) Timeout .2
Enddo
nDataLen = oTCPIP.oleWinsock.object.BytesReceived()
oTCPIP.oleWinsock.object.GetData(@cReceivedData,nDataLen)
* Is the email server ready for data?
If Left(cReceivedData,3) = &quot;354&quot;
* Yes, Send in data!
oTCPIP.oleWinsock.object.SendData(&quot;Subject: &quot;+;
cSubject+Chr(13)+Chr(10) + ;
&quot;From: &quot; + cFrom +Chr(13)+Chr(10) + ;
&quot;To: &quot; + cTo +Chr(13)+Chr(10) + ;
+Chr(13)+Chr(10) + ;
cBody+Chr(13)+Chr(10) + ;
&quot;.&quot;+Chr(13)+Chr(10))
Do While oTCPIP.oleWinsock.object.BytesReceived() < 4
Wait Window Chr(13)+Chr(10)+&quot; Sending Email>>>>>>.&quot;+;
Chr(13)+Chr(10) Timeout 2
Enddo
nDataLen = oTCPIP.oleWinsock.object.BytesReceived()
oTCPIP.oleWinsock.object.GetData(@cReceivedData,nDataLen)
oTCPIP.oleWinsock.object.SendData(&quot;quit&quot;+Chr(13)+Chr(10))
Else
* No. We didn't get a '354' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No. We didn't get a '250' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No. We didn't get a '250' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No. We didn't get a '220' back!
* Report Error and terminate.
cErrorMsg = cReceivedData
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* No, connection failed.
cErrorMsg = &quot;Failed to Connect to E-Mail Server<Mail.YourSMTPserver.Com> on Port<25>!&quot;
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Else
* Yes, Error Occurred. Couldn't create object.
On Error
cErrorMsg = Message()
Wait Window cErrorMsg Time 10
lStatus = .F.
Endif
Release oTCPIP
Endfor
Endif
* Reset the &quot;Set Exact&quot; value
Set Exact &cExact
* Return the Status Value
Return lStatus
EndFunc
***********************************************************************************
* END SendEmail()
***********************************************************************************

Now, this will work! Sorry it took so long to get back with an answer. Work can be such a bother! I had to save face and fix the problem. And save everyone $100 on a third party product that you don't need for simple email notification.

Good Luck. Have Fun!

Allen &quot;Uncanny&quot; Schott





 
Hi all
I use the code posted by uncany and work perfect.
But i have many questions
1) how i need make to send mail with attachment and html content.
2) How to send log and pass from access to mail count.(that is necesary from any servers qhen i conect from another provider)
3) Can i recive mails fromm pop3 with winsock???. What is the way to make it?
Tnx a lot
 
Victor,

This code was posted by mgagnon in thread184-292050

Maybe this is all you need... it uses the computer's default e-mail.

*****************
DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, STRING cAction, STRING cFileName, ;
STRING cParams, STRING cDir, INTEGER nShowWin

lcMail = &quot;mailto:john@mycompany.com&quot;+ ;
&quot;?CC= boss@mycompany.com&Subject= Meet for lunch&quot;+ ;
&quot;&Body= Please join me for a sandwich at noon.&quot;
ShellExecute(0,&quot;open&quot;,lcMail,&quot;&quot;,&quot;&quot;,1)
*****************
 
Tnx Baltman
But i need make that without use the computer's default e-mail.
Direct connection between app and smtp and pop3 servers.
Tnx again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top