Interface to create and send e-mails

Description

Emails contain plain text, possible HTML text with images and further attachments. The creation and collection of all this data is not an easy task. If a document contains embedded images, first image files have to be created so the HTML part of the e-mail can link to them.

 

Please note, this interface is currently not working with Visual Basic 6. It can be used with VS2008.

 

Please also see Memo.SaveToFile - it may be more suitable when working with MS OutLook then using MAPI.

 

The TextDynamic interface IWPMAPI makes it easy to prepare the e-mail data. You are then free to either use the MapiSendMail function to send it (call Send) or you can read the properties and send the e-mail using a different tool. In this case you only have to interpret the list provided by AttachmentList.

 

When you execute Prepare the e-mail will be created, all attachments will be written. By default the e-mail will be created with the body as ANSI text and the document as HTML attachment. If you want the e-mail body to be HTML formated text, first assign the string "<html>" to the property Body .

 

Important properties:

Body: The body as ANSI text, assign <html> to force HTML creation, assign "" to let the component create ANSI text. You can also assign some ANSI text will be then used as text body.

 

AddHTML: if true (default) the document will be appended as HTML attachment.

 

AttachmentList: the attachment files as list of filename=displayname pairs, delimited by comma. Prepare clears this list and adds the name of the HTML message and all images. If you want to add other files you can use AppendFile after preparing.

 

Important methods:

Prepare: Collect the data for an e-mail. This clears the attachment list.

 

Send: Send the e-mail which was prepared last. If no e-mail was prepared the document from editor 1 will be send to the e-mail client. (Internally the Windows API MAPISendMail is used. The parameter lhSession is passed as 0, ulUIParam can be set using the method SetAppHandle, lpMessage will be automatically prepared and flFlags can be set using the property MAPIFlags)

 

Send2: Send the e-mail which was prepared last. If no e-mail was prepared the document from editor 2 will be send to the e-mail client.

 

Clear: Resets the properties Subject, FromName, FromAddress, Recipients, CCList, BCCList, AttachmentList, Body.

C#:

   IWPMapi mapi;

   mapi = wpdllInt1.MAPI;

   if (mapi!=null)

   {

       mapi.Recipients = "somebody@somewhere.com";

       mapi.AddCCRecipient("Julian""julian@somewhere.com");

       mapi.AddCCRecipient("Claudia""claudia@somewhere.com");

       mapi.Subject = "Test me";

       mapi.Body = "<html>";

       mapi.Prepare(1,0);

       MessageBox.Show(

            mapi.AttachmentList,

            "MAPI created this attachments");

          mapi.Send();

   }

 

VB.NET

        Dim mapi As WPDynamic.IWPMapi

        mapi = WpdllInt1.MAPI

 

        mapi.Recipients = "somebody@somewhere.com"

        mapi.AddCCRecipient("Julian", "julian@somewhere.com")

        mapi.AddCCRecipient("Claudia", "claudia@somewhere.com")

        mapi.Subject = "Test me"

        mapi.Body = "<html>"

        mapi.Prepare(1, 0)

        MessageBox.Show(mapi.AttachmentList, "MAPI created this attachments")

        mapi.Send()

 

 

Note

There is another possibility to create an e-mail. You can use the integrated MIME writer class. If you use the method SaveToString with the format name "MIME" it will create multipart MIME e-mail data with the HTML code and all images embedded without a single temporary file beeing created! The e-mail fields "From", "To", "CC", "BCC" and "Subject" will be use the value from the respective properties in the MAPI interface.

 

The MIME writer uses functions of the free library Synapse at http://www.ararat.cz/synapse/

 

Properties


Methods

 


[idh_interface_iwpmapi.htm]    Copyright © 2007 by WPCubed GmbH