Board index » delphi » creating email

creating email


2005-06-15 08:38:38 PM
delphi167
I have this Delphi 6 application that creates reports. It also uses a table
of names which includes an email address. I'd like to send a copy
of a report to the names in the list. I can export the report to a text
file to use as an attachment. Is there a programable interface
available to mail programs? Is there any documentation I can read that
will describe how to do this? ( Currently I am using FireFox. )
 
 

Re:creating email

Terry writes:
Quote
I have this Delphi 6 application that creates reports. It also uses a table
of names which includes an email address. I'd like to send a copy
of a report to the names in the list. I can export the report to a text
file to use as an attachment. Is there a programable interface
available to mail programs? Is there any documentation I can read that
will describe how to do this? ( Currently I am using FireFox. )
Here's what I have been using. It uses the default mail program, whatever that may be. To send to
multiple people, create a string variable holding all the email addresses and separate them with a
semi-colon.
{SendMail function modified from one found at www.scalabium.com/faq/dct0115.htm}
uses MAPI;
function SendMail(const Subject, Body, FileName, RecipientName, RecipientEmail: string): Integer;
var Email: TMapiMessage;
lpRecipient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;
SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
FillChar(Email,SizeOf(Email),0);
with Email do begin
if Subject<>'' then lpszSubject:=PChar(Subject);
if Body<>'' then lpszNoteText:=PChar(Body);
if RecipientEmail<>'' then begin
lpRecipient.ulRecipClass:=MAPI_TO;
if RecipientName='' then lpRecipient.lpszName:=PChar(RecipientEmail)
else lpRecipient.lpszName:=PChar(RecipientName);
lpRecipient.lpszAddress:=PChar('SMTP:'+RecipientEmail);
lpRecipient.ulReserved:=0;
lpRecipient.ulEIDSize:=0;
lpRecipient.lpEntryID:=nil;
nRecipCount:=1;
lpRecips:=@lpRecipient;
end
else lpRecips:=nil;
if (FileName='') then begin
nFileCount:=0;
lpFiles:=nil;
end
else begin
FillChar(FileAttach,SizeOf(FileAttach),0);
FileAttach.nPosition:=Cardinal($FFFFFFFF);
FileAttach.lpszPathName:=PChar(FileName);
nFileCount:=1;
lpFiles:=@FileAttach;
end;
end;
MAPIModule:=LoadLibrary(PChar(MAPIDLL));
if MAPIModule=0 then Result:=-1
else
try
@SM := GetProcAddress(MAPIModule,'MAPISendMail');
if @SM<>nil then Result:= SM(0,Application.Handle,Email,MAPI_DIALOG or MAPI_LOGON_UI,0)
else Result:=1;
finally
FreeLibrary(MAPIModule);
end;
if Result<>0 then MessageDlg('Email was not sent',mtError,[mbOK],0);
end;
 

Re:creating email

Another alternative is to use the Indy SMTP component. I have used it
is several applications and it works very well.
--
Bill Todd (TeamB)
Terry writes:
Quote
I have this Delphi 6 application that creates reports. It also uses a
table of names which includes an email address. I'd like to send
a copy of a report to the names in the list. I can export the report
to a text file to use as an attachment. Is there a programable
interface available to mail programs? Is there any documentation I
can read that will describe how to do this? ( Currently I am using
FireFox. )