Due to a deafening roar of requests that the vfpexmap.fll support HTML, I have created an update that includes an additional function called EMCreateMessageEx (not to be confused with the EMCreateMessage function used to send plain text). This new function provides the ability to send HTML and RTF emails. I’ve updated my previous blog entry that contains the complete documentation and example code. Here’s a link to the new FLL (all other links to vfpexmapi.zip on this blog also point to this updated file, so no need to worry about where you get it from here), an example of use in VFP, and the documentation for the new function…
Download Visual FoxPro Extended MAPI FLL (size 10 KB approx.)
#define MAPI_ORIG 0
#define MAPI_TO 1
#define MAPI_CC 2
#define MAPI_BCC 3
#define IMPORTANCE_LOW 0
#define IMPORTANCE_NORMAL 1
#define IMPORTANCE_HIGH 2
CLEAR
LOCAL lcHTML, lcRTF
SET LIBRARY TO LOCFILE(“vfpexmapi.fll”)
*****************************
*!* Send HTML Email
*****************************
TEXT TO m.lcHTML NOSHOW
<html>
<body>
<p>Here’s an HTML email.</p>
<ul>
<li>The</li>
<li><a href=“http://www.sweetpotatosoftware.com/SPSBlog/”>SPS Weblog</a></li>
<li>is Back.</li>
</ul>
<p>Visual FoxPro Rocks!</p>
</body>
</html>
ENDTEXT
?
?“Sending HTML Email”
?EMCreateMessageEx(“HTML Test”, m.lcHTML, IMPORTANCE_HIGH)
?EMAddRecipient(“someone@somedomain.com”, MAPI_TO)
?EMSend()
*****************************
*!* Send RTF Email
*****************************
TEXT TO m.lcRTF NOSHOW
{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard
Here is a {\b Rich Text Format} email.\par
}
ENDTEXT
?
?“Sending RTF Email”
?EMCreateMessageEx(“RTF Test”, m.lcRTF, IMPORTANCE_LOW)
?EMAddRecipient(“someone@somedomain.com”, MAPI_TO)
?EMSend()
Function EMCreateMessageEx()
Signature: EMCreateMessageEx(cSubject, cHtmlOrRtfBody, nImportance)
Parameters:
cSubject – subject line of the email
cHtmlOrRtfBody – body of the email formatted in HTML or RTF
nImportance – level of importance for the email – valid values for this parameter are as follows:
0 = Low Importance
1 = Normal Importance
2 = High Importance
Return Value:
Logical – indicating whether the message was successfully created – .T. for success and .F. for failure
Remarks:
This function creates the email message that is going to be sent and should be called first before adding recipients and/or attachments. This function is an advanced version of EMCreateMessage providing for either HTML or RTF within the body of the email. Ensure that the cHtmlOrRtfBody parameter contains complete HTML or RTF as shown in the example above. In short, the opening and closing tags are required as they are used to determine what format was used for the body.