Microsoft KB Archive/175052

= HOWTO: Send a Message in Visual FoxPro Using Active Messaging =

Article ID: 175052

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Collaboration Data Objects 1.1

-



This article was previously published under Q175052



SUMMARY
This article provides two small code samples using Active Messaging from Visual FoxPro.

It is the intention of the author of this article to make you, the developer, aware that you have the option of Active Messaging available to you in order to implement messaging functionality in your applications.

While this article is designed as a mere introduction to demonstrate just the most basic functionality of the Active Messaging Library, you should be aware that the Active Messaging Library is very robust, much more so than the vast majority of Messaging Controls.

For additional information, please see the following article in the Microsoft Knowledge Base:

171440 Where to Acquire the Collaboration Data Objects Library



MORE INFORMATION
This first sample is a minimal scenario providing just enough to construct and send a message: * AM_BareBones.PRG *   *   *Create a MAPI Session object then Logon. The Logon dialog can be  *bypassed by providing a valid ProfileName as the first parameter *(as a string) to the Logon Method. objSession = CREATEOBJECT("mapi.session") objSession.Logon

*Create a new message in the Outbox objMessage = objSession.Outbox.Messages.Add

*Populate a few basic properties of the message objMessage.Subject = "This is the subject" objMessage.Text = "This is the message text"

*Add a Recipient to the message we just created and resolve objRecip = objMessage.Recipients.Add *Alias of who you are sending to  objRecip.name = "TargetEmailName" objRecip.Resolve

*Send it  objMessage.Send

*Clean up then bail objSession.Logoff RELEASE objRecip, objMessage, objSession *EOP: AM_BareBones.PRG The second sample is similar to the first except that it adds an attachment to the outgoing message. This sample also demonstrates a few alternate ways that the same functionality can be accomplished without using the same code. For instance, logging on and passing a ProfileName instead of getting prompted to enter one, or the slightly different manner in which the recipient is added. * AM_Attachments.PRG * --  *   *Create a MAPI Session object then Logon. The Logon dialog can be  *bypassed by providing a valid ProfileName as the first parameter *(as a string) to the Logon Method as seen below. objSession = CREATEOBJECT("mapi.session") objSession.Logon("YourProfileName")

*Create a new message in the Outbox and populate a few basic properties objMessage = objSession.Outbox.Messages.Add objMessage.Subject = "Visual Fox Active Messaging Sample - Attachments" objMessage.Text = "This is the message text."

*Add an attachment (assumes "myfile.doc" exist in c:\) objMessage.Attachments.Add("MyFile.doc", 0, 1, "c:\myfile.doc")

*Add a Recipient to the message we just created and resolve objRecip = objMessage.Recipients.Add("TargetsEmailName") && who it's to  objRecip.Resolve

*Send it  objMessage.Send

*Clean up then bail objSession.Logoff RELEASE objRecip, objMessage, objSession *EOP: AM_Attatchments.PRG

