3
votes

In this question I just asked I told that I prepare Outlook messages by sending data from my app to Outlook with MAPI.

But in this way I have one major hurdle: I cannot send formatted text for the message body. My form has an rtf field, I strip away rtf data then prepare the outlook mail.

How is it possible to do the same (creating an outlook outgoing email ready to be sent) without using mapi, and keeping the formatting, somehow "rtf to html"... Does anyone already have this code?

3
Why do you believe the use of MAPI is related to the use of formatting? Seems orthogonal to me.Paul-Jan
Do you really need to use Outlook to compose and send the email? Why not send it directly through an SMTP service, using Indy and IdSmtp?Warren P
@Paul-Jan I am not a MAPI expert, I just use code written by someone else that prepares an email to be sent by outlook. So for me MAPI is new world and I could study it but I am asking questions to avoid studying useless things.LaBracca
@Warren P No I use both. I give the option to the user to send directly (with IdSmtp as you said) or through Outlook. There are 2 buttons. Why this? For historical reasons (let's say "backwards userfriendliness compatibility").LaBracca

3 Answers

4
votes

Using the Ole Automation Server component wrappers provided by Delphi. An example I dug up for another question recently can be found here: Easiest way to compose Outlook 2010 mail from Delphi?

3
votes

You can use Microsoft's Collaboration Data Objects but it is limited by the Outlook Security Patch. The Redemption Data Objects that are part of Outlook Redemption works around the Security patch. I have used RDO to create RTF emails in Outlook.

Here is a sample procedure using RDO to create an email, insert RTF formatted text and display the email so it can be edited before sending.

procedure TForm1.RTFemail;
var
  Session, Drafts, Mail, Recip: OleVariant;
  s : string;
begin
  Session := CreateOleObject('Redemption.RDOSession');
  Session.Logon;
  Drafts := Session.GetDefaultFolder(olFolderDrafts);
  Mail := Drafts.Items.Add;
  Recip := Mail.Recipients.Add('[email protected]');
  Recip.Type := olTo;
  Recip.Resolve;
  Mail.Subject := 'Testing Redemption';
  s := '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil'+
    '\fcharset0 Arial;}}\viewkind4\uc1\pard\fs16 This is \ul '+
    'underlined\ulnone , \i italic\i0 , and \b bold\b0 .\par }';
  Mail.RTFBody := s;
  Mail.Save;
  Mail.Display;
end;

It produces the following with Outlook 2003

enter image description here

0
votes

Exchange Web Services (EWS) were introduced in Exchange 2007 as an alternative to the MAPI protocol, it is a documented SOAP based protocol.

I guess it will not launch or activate the Outlook client but it is be possible to create a new E-mail message in the "Draft" folder (see CreateItem refrence).

The Body element documentation shows that plain text and HTML are supported.