MAPI + Body HTML + Attachments

MAPI + Body HTML + Attachments

Post by Beto Net » Wed, 14 Jun 2006 02:40:07


How can I create a email using MAPI with the body as HTML and with any
attachments ?

Thank's!
 
 
 

MAPI + Body HTML + Attachments

Post by Andrew Jam » Wed, 14 Jun 2006 03:25:28

ere's some old code that I wrote a few years ago ...

unit ajMAPI;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Mapi;

type
TajMapiErrorEvent = procedure(Sender : TObject; ErrCode : integer) of
object;

TajMapiControl = class(TComponent)
public
constructor Create (AOwner : TComponent); override;
destructor Destroy; override;
private
fSubject : string;
fMailText : string;
fFromName : string;
fFromAddress : string;
fTOAddress : TStrings;
fCCAddress : TStrings;
fBCCAddress : TStrings;
fAttachedFileName : TStrings;
fDisplayFileName : TStrings;
fShowDialog : boolean;
fOnUserAbort : TNotifyEvent;
fOnMapiError : TajMapiErrorEvent;
fOnSuccess : TNotifyEvent;
procedure SetToAddress (Value : TStrings);
procedure SetCCAddress (Value : TStrings);
procedure SetBCCAddress (Value : TStrings);
procedure SetAttachedFileName (Value : TStrings);
protected
public
procedure SendMail;
procedure Reset;
published
property Subject : string read fSubject
write fSubject;
property Body : string read fMailText
write fMailText;
property FromName : string read fFromName
write fFromName;
property FromAddress : string read fFromAddress
write fFromAddress;
property Recipients : TStrings read fTOAddress
write SetTOAddress;
property CopyTo : TStrings read fCCAddress
write SetCCAddress;
property BlindCopyTo : TStrings read fBCCAddress
write SetBCCAddress;
property AttachedFiles : TStrings read fAttachedFileName
write SetAttachedFileName;
property DisplayFileName : TStrings read fDisplayFileName;
property ShowDialog : boolean read fShowDialog
write fShowDialog;

property OnUserAbort : TNotifyEvent read fOnUserAbort
write fOnUserAbort;
property OnMapiError : TajMapiErrorEvent read fOnMapiError
write fOnMapiError;
property OnSuccess : TNotifyEvent read fOnSuccess
write fOnSuccess;
end;

procedure Register;

implementation

{--------------------------------------------------------------------------------------------------}

constructor TajMapiControl.Create(AOwner : TComponent);
begin
inherited;
fOnUserAbort := nil;
fOnMapiError := nil;
fOnSuccess := nil;
fSubject := '';
fMailtext := '';
fFromName := '';
fFromAddress := '';
fTOAddress := TStringList.Create;
fCCAddress := TStringList.Create;
fBCCAddress := TStringList.Create;
fAttachedFileName := TStringList.Create;
fDisplayFileName := TStringList.Create;
fShowDialog := false;
end; {constructor}

{--------------------------------------------------------------------------------------------------}

destructor TajMapiControl.Destroy;
begin
fTOAddress.Free;
FCCAddress.Free;
FBCCAddress.Free;
fAttachedFileName.Free;
fDisplayFileName.Free;
inherited;
end; {destructor}

{--------------------------------------------------------------------------------------------------}

procedure TajMapiControl.SetToAddre
 
 
 

MAPI + Body HTML + Attachments

Post by Beto Net » Wed, 14 Jun 2006 03:38:14

k, thank's, but it doesn't works!!!

Try this to confirm:
procedure TForm1.Button3Click(Sender: TObject);
var
Email: TajMapiControl;
begin
Email := TajMapiControl.Create(Self);
try
Email.ShowDialog := True;
Email.Recipients.Add(' XXXX@XXXXX.COM ');
Email.Subject := 'Any';
with TStringList.Create do
try
LoadFromFile('C:\MyBody.html');

Email.Body := Text;
finally
Free;
end;
Email.AttachedFiles.Add('C:\a_file.exe');
Email.SendMail;
finally
Email.Free;
end;
end;




"Andrew Jameson" < XXXX@XXXXX.COM > escreveu na mensagem
news: XXXX@XXXXX.COM ...
Dialogs,
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}
fTOAddress.Strings[lp1]);
fCCAddress.Strings[lp1]);
SizeOf(TMapiFileDesc));
{---------------------------------------------------------------------------
-----------------------}
{---------------------------------------------------------------------------
-----------------------}


 
 
 

MAPI + Body HTML + Attachments

Post by Andrew Jam » Wed, 14 Jun 2006 04:49:14

To send the body in html then you need to pass the html file name as the
first attachment :

MapiControl.AttachedFiles.Add('C:\MyBody.html');

Why is when you try to help that someone comes back and says 'it doesn't
work' without further elaboration ? Software support / assistance is not
helped by such brickwall comments !

So not being telepathic nor clairvoyant, I've had to guess that it's the
HTML as the body that was giving the problem. There's loads of MAPI stuff
around but we stopped using it as the later versions of Outlook Express now
have a security dialog that can't be overridden.

Also, it's not good etiquette replying without t *** off what's no longer
needed in the reply.

Andrew
 
 
 

MAPI + Body HTML + Attachments

Post by Team » Wed, 14 Jun 2006 04:52:20


You can't. Mapi does not support HTML. You would have to use SMTP directly
for that.


The MapiMessage structure has nFileCount and lpFiles members for controlling
that. Essentially, you have to provide the message with an array of
MapiFileDesc structures describing each file.


Gambit
 
 
 

MAPI + Body HTML + Attachments

Post by Mike » Wed, 14 Jun 2006 21:02:07


Extended MAPI can bypass the security popup.
Mike
 
 
 

MAPI + Body HTML + Attachments

Post by Andrew Jam » Wed, 14 Jun 2006 22:58:26

Thanks for that Mike ... might revisit MAPI again when time permits !

Andrew
 
 
 

MAPI + Body HTML + Attachments

Post by Beto Net » Wed, 14 Jun 2006 23:47:26

Where can I download a sample about using Extended MAPI to resolve my
problem?



"Andrew Jameson" < XXXX@XXXXX.COM > escreveu na mensagem
 
 
 

MAPI + Body HTML + Attachments

Post by Frans van » Thu, 15 Jun 2006 18:49:41


try the mapi component by www.rapware.nl
 
 
 

MAPI + Body HTML + Attachments

Post by Mike » Fri, 16 Jun 2006 01:48:34


Check out EasyMAPI at http://www.yqcomputer.com/
You can download a free trial, and examples. Their support is also very good.
Mike