Article ID: | qGEN015 |
Date Revised: | January 09, 1999 |
Keywords: | MAPI, E-Mail |
See Also: | qGEN017 |
Question: How can I send E-Mail from a VFP application?
Answer: Here's some sample code showing how to use the MAPI controls that ship with VFP to send a message and to look at the contents of the Inbox. For more information look at the MAPI96.HLP file in the \Windows\System folder.
activate window "debug output"
* simple test email program using MAPI
oleMAPISession = createobject( "MSMAPI.MAPISession.1" )
* Signon to mail
with oleMAPISession
.UserName = "Test"
.Password = ""
.Signon()
* Check the SignOn status
if ( .SessionID > 0 )
oleMAPIMessages = createobject( "MSMAPI.MAPIMessages.1" )
* tell the message the SessionID
oleMAPIMessages.SessionID = .SessionID
debugout "Successful mail log on"
else
debugout "Mail login failed"
return
endif
endwith
* Send an email
with oleMAPIMessages
.Compose()
* Set the Recipient name and resolve
.RecipDisplayName = "DavidFrankenbach@worldnet.att.net"
.RecipType = 1
.ResolveName()
.MsgSubject = "This is the Subject"
.MsgNoteText = "This is the email text"
.Send( .f. )
endwith
* Read the InBox
with oleMAPIMessages
.Fetch()
for i = 0 to .MsgCount-1
.MsgIndex = i
debugout .MsgSubject
endfor
endwith
* Signoff
oleMAPISession.Signoff()