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 strongm 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 a VFP 6 application to send e-mail ? 1

Status
Not open for further replies.

michel392

Programmer
Dec 17, 2001
54
BR
My VFP application prints billing reports to be sent to customers. As I have a field in the application for the customer's e-mail, I would like the application to automatically send the billing reports directly to the customers e-mails. Is there a simple way to accomplish this in VFP 6 ?
Thanks,
Michel
 
Hi Michel,

I posted some code in the following thread you might find useful... it will give you some options. Here's the link...

Emailling from within VFP
thread1251-797973



boyd.gif

SweetPotato Software Website
My Blog
 
Thank you Craig for your valuable help !
The code you provide in the thread worked fine ! I can now send e-mail from my VFP 6 application.

But unhappily I was not able to send an attachment !
I named the attachment in the line:
aryAttach(1) = "c:\tests\phonedir.pdf"
but the "phonedir.pdf" was not attached

Note: it was possible to send the e-mail just through
CASE tcType = 1
llEmailStatus = SendViaMAPI(tcFrom, tcTo, tcSubject, tcBody)
lcType = "MAPI"

Thanks again !
Michel
 
Hi Michel,

Sorry about that... my excuse is the code was written really quick for that example. Here's the more complete SendViaMAPI function that will allow for attachments...
Code:
*!* Sample Use of SendViaMAPI
DIMENSION aryAttachments(2)
aryAttachments(1) = "C:\test1.txt"
aryAttachments(2) = "C:\test2.txt"
IF SendViaMAPI("me@myhost.com", "someone@theirhost.com", "My Subject Line", "My Email Body", @aryAttachments)
	MESSAGEBOX("Email sent successfully!")
ELSE
	MESSAGEBOX("Problem sending email!")
ENDIF

****************************************************
FUNCTION SendViaMAPI(tcFrom, tcTo, tcSubject, tcBody, taFiles)
****************************************************
    ON ERROR RETURN(.F.)
    LOCAL loSession, loMessages
    loSession = CREATEOBJECT( "MSMAPI.MAPISession" )
    loSession.Signon()
    IF (loSession.SessionID > 0)
        loMessages = CREATEOBJECT( "MSMAPI.MAPIMessages" )
        loMessages.SessionID = loSession.SessionID
    ENDIF
    WITH loMessages
        .Compose()
        .RecipDisplayName = tcTo
        .RecipType = 1
        .ResolveName()
        .MsgSubject = tcSubject
        .MsgNoteText = tcBody
	 IF PCOUNT() > 4
	            FOR lnCountAttachments = 1 TO ALEN(taFiles)
					.AttachmentIndex = .AttachmentCount
					.AttachmentName = JUSTFNAME(taFiles(lnCountAttachments))
					.AttachmentPosition = .AttachmentIndex
					.AttachmentPathName = taFiles(lnCountAttachments)
	            ENDFOR
	ENDIF
       .SEND(.F.) && send in .T. to not send email automatically but instead see it in outlook
    ENDWITH
    loSession.Signoff()
    STORE .NULL. to loSession, loMessages
    RELEASE loSession, loMessages
    RETURN .T.
ENDFUNC

boyd.gif

SweetPotato Software Website
My Blog
 
Dear Craig:

The routine you provided works fine with the attachments ! I'm so glad for the fact that now I can send e-mail with attachments from a VFP program. From now, I am going to insert the routine inside some of my applications.

Some doubts:
1) When VFP created executable files, it gave the following error:
Unknown TAFILES - Undefined
I tried use the PUBLIC TAFILES command in the beginning of the program, but the error showed again.

2) Can I change the contents of the tcBody variable, so I can send HTML text (so the message can be displayed with head, bold, italic, colors, etc) ?

Thank you !

Michel
 
Hi Craig !

It worked fine, thanks again !

I copied the very same application program (which now uses your routine above) to my other computer (which has the same Windows 98 SE, and the same Outlook Express 5). When my application program is executed, in order to send message and attachment to the Outlook Express Outbox, it shows the error message from the routine ("Problem sending email!").

I tried to solve the problem during this whole Saturday and I'm frustrated I have not got a solution, even after installing the Windows Messaging in this other computer. My application program remains showing the same error, only in this computer.

Is there anything I can check ?

Thanks,
Michel
 

Have you checked with a "set step on" where the function returns a false?. I tried Craig's function and got an error myself because I was trying to send one file rather than 2 as in his example, but I hadn't changed the array size in the first line. Try a set step and see where it generates an error.



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I have uninstalled and reinstalled the Outlook Express 5, and now the error is: "Outlook Express is incorrect installed..."
It looks the communication between my application program and the outbox mail in the Outlook Express is faulty.

Michel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top