3

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?

Community
  • 1
  • 1
UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • 1
    Why do you believe the use of MAPI is related to the use of formatting? Seems orthogonal to me. – Paul-Jan Feb 05 '11 at 15:14
  • 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 Feb 07 '11 at 03:07
  • @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. – UnDiUdin Feb 07 '11 at 08:03
  • 1
    @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"). – UnDiUdin Feb 07 '11 at 08:04

3 Answers3

4

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?

Community
  • 1
  • 1
Marjan Venema
  • 19,136
  • 6
  • 65
  • 79
3

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('nobody@gmail.com');
  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

crefird
  • 1,590
  • 11
  • 17
  • Note that redemption does so through MAPI. That said, the 'no mapi' requirement is probably irrelevant. – Paul-Jan Feb 05 '11 at 21:38
  • Redemption uses Extended Mapi which is not affected by the security patch. – Remko Feb 05 '11 at 22:34
  • It looks like CDO is deprecated: "Starting with Exchange 2007, neither the Messaging API (MAPI) client libraries nor CDO 1.2.1 are provided as a part of the base product installation." - http://en.wikipedia.org/wiki/Collaboration_Data_Objects – mjn Feb 06 '11 at 18:57
  • Redemption RDO uses MAPI so you do not have to. I have added a sample procedure and screen shot of the email it creates. – crefird Feb 09 '11 at 00:14
0

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.

mjn
  • 36,362
  • 28
  • 176
  • 378