Goodangel Matope
asked on
Delphi Application fax service / api win 2000
I am creating an application that I want to print to the windows fax service, automatically using a fax number extracted from a database table. I want to use the windows 2000 fax service if possible. How can I do this in delphi code? I know I can set the printer index to the fax printer, but this will only bring up the fax wizard. I want to use a fax number from the application.
Regards
Gee!
Regards
Gee!
I think the fax service is registered as a DDE service and can be accessed using a DDe client components .
ASKER
How do I do this, I have no idea, please assist!
Actually there is an easier way of doing this. If you are using microsoft outlook then you can send a fax simply by sending an email using mapisendmail. You put the fax number in the To: item.
To enable outlook to send faxes all you do is File New Fax and you will be prompted for the outlook cd to add the fax software components.
I can post some mapi mail samples if you want to install the outlook fax software and send using email
To enable outlook to send faxes all you do is File New Fax and you will be prompted for the outlook cd to add the fax software components.
I can post some mapi mail samples if you want to install the outlook fax software and send using email
Here is some mapi code to send an email too outlook as a fax , the email part was posted on another question recently . I cannot find it anymore but it is someone elses code I have modified, apologies for this.
Remember you must install the fax software in outlook. You can also send the fax to someone in the address book also.
procedure TSMTPForm.Button1Click(Sen der: TObject);
var
R: cardinal;
mail: TStringList;
begin
mail:=tstringlist.create;
try
mail.values['to']:='FAX@01 224878484' ;
mail.values['Subject']:='m y fax subject';
mail.values['body']:='my fax body';
R:=sendEMail(Application.H andle,mail );
finally
mail.free;
end;
end;
function TSMTPForm.SendEMail(Handle :THandle;Mail :TStrings) :Cardinal;
type
TAttachAccessArray = array [0..0] of TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;
var
MapiMessage : TMapiMessage;
R: array [0..2 ] of TMapiRecipDesc;
Attachments : PAttachAccessArray;
AttachCount : Integer;
i1 : integer;
FileName : String;
begin
fillChar(MapiMessage,SizeO f(MapiMess age),#0);
Attachments := nil;
fillChar(R[0],SizeOf(R[0]) , #0);
fillChar(R[1],SizeOf(r[0]) , #0);
if Mail.Values['to'] <> '' then begin
R[0].ulReserved := 0;
R[0].ulRecipClass := MAPI_TO;
R[0].lpszName := StrNew(PChar(Mail.Values[' to']));
R[0].lpszAddress := StrNew(PChar('SMTP:' +Mail.Values['to']));
R[0].ulEIDSize := 0;
MapiMessage.nRecipCount := 1;
MapiMessage.lpRecips := @R;
end;
if Mail.Values['Cc'] <> '' then begin
R[1].ulReserved := 0;
R[1].ulRecipClass := MAPI_CC;
R[1].lpszName := StrNew(PChar(Mail.Values[' Cc']));
R[1].lpszAddress := StrNew(PChar('SMTP:' +Mail.Values['Cc']));
R[1].ulEIDSize := 0;
inc(MapiMessage.nRecipCoun t);
MapiMessage.lpRecips := @R;
end;
AttachCount := 0;
for i1 := 0 to MaxInt do begin
if Mail.Values['attachment'+i nttostr(i1 )] = '' then
break;
inc(AttachCount);
end;
if AttachCount > 0 then begin
GetMem(Attachments, SizeOf(TMapiFileDesc) * AttachCount);
for i1 := 0 to AttachCount -1 do begin
FileName := Mail.Values['attachment'+i nttostr(i1 )];
Attachments[i1].ulReserved := 0;
Attachments[i1].flFlags := 0;
Attachments[i1].nPosition := ULONG($FFFFFFFF);
Attachments[i1].lpszPathNa me := StrNew(PChar(FileName));
Attachments[i1].lpszFileNa me :=StrNew(PChar(ExtractFile Name(FileN ame)));
Attachments[i1].lpFileType := nil;
end;
MapiMessage.nFileCount := AttachCount;
MapiMessage.lpFiles := @Attachments^;
end;
if Mail.Values['subject'] <> '' then
MapiMessage.lpszSubject := StrNew(PChar(Mail.Values[' subject']) );
if Mail.Values['body'] <> '' then
MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values[' body']));
Result := MapiSendMail(0,Handle ,MapiMessage,MAPI_DIALOG*O rd(Handle< >0) or
MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
// use this if you don't want the dialog box to come up
//Result := MapiSendMail(0,Handle ,MapiMessage,0, 0);
for i1 := 0 to AttachCount-1 do begin
strDispose(Attachments[i1] .lpszPathN ame);
strDispose(Attachments[i1] .lpszFileN ame);
end;
if assigned(MapiMessage.lpszS ubject) then
strDispose(MapiMessage.lps zSubject);
if assigned(MapiMessage.lpszN oteText) then
strDispose(MapiMessage.lps zNoteText) ;
if assigned(R[0].lpszAddress) then strDispose(R[0].lpszAddres s);
if assigned(R[0].lpszName) then strDispose(R[0].lpszName);
if assigned(R[1].lpszAddress) then strDispose(R[1].lpszAddres s);
if assigned(R[1].lpszName) then strDispose(R[1].lpszName);
end;
Remember you must install the fax software in outlook. You can also send the fax to someone in the address book also.
procedure TSMTPForm.Button1Click(Sen
var
R: cardinal;
mail: TStringList;
begin
mail:=tstringlist.create;
try
mail.values['to']:='FAX@01
mail.values['Subject']:='m
mail.values['body']:='my fax body';
R:=sendEMail(Application.H
finally
mail.free;
end;
end;
function TSMTPForm.SendEMail(Handle
type
TAttachAccessArray = array [0..0] of TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;
var
MapiMessage : TMapiMessage;
R: array [0..2 ] of TMapiRecipDesc;
Attachments : PAttachAccessArray;
AttachCount : Integer;
i1 : integer;
FileName : String;
begin
fillChar(MapiMessage,SizeO
Attachments := nil;
fillChar(R[0],SizeOf(R[0])
fillChar(R[1],SizeOf(r[0])
if Mail.Values['to'] <> '' then begin
R[0].ulReserved := 0;
R[0].ulRecipClass := MAPI_TO;
R[0].lpszName := StrNew(PChar(Mail.Values['
R[0].lpszAddress := StrNew(PChar('SMTP:' +Mail.Values['to']));
R[0].ulEIDSize := 0;
MapiMessage.nRecipCount := 1;
MapiMessage.lpRecips := @R;
end;
if Mail.Values['Cc'] <> '' then begin
R[1].ulReserved := 0;
R[1].ulRecipClass := MAPI_CC;
R[1].lpszName := StrNew(PChar(Mail.Values['
R[1].lpszAddress := StrNew(PChar('SMTP:' +Mail.Values['Cc']));
R[1].ulEIDSize := 0;
inc(MapiMessage.nRecipCoun
MapiMessage.lpRecips := @R;
end;
AttachCount := 0;
for i1 := 0 to MaxInt do begin
if Mail.Values['attachment'+i
break;
inc(AttachCount);
end;
if AttachCount > 0 then begin
GetMem(Attachments, SizeOf(TMapiFileDesc) * AttachCount);
for i1 := 0 to AttachCount -1 do begin
FileName := Mail.Values['attachment'+i
Attachments[i1].ulReserved
Attachments[i1].flFlags := 0;
Attachments[i1].nPosition := ULONG($FFFFFFFF);
Attachments[i1].lpszPathNa
Attachments[i1].lpszFileNa
Attachments[i1].lpFileType
end;
MapiMessage.nFileCount := AttachCount;
MapiMessage.lpFiles := @Attachments^;
end;
if Mail.Values['subject'] <> '' then
MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['
if Mail.Values['body'] <> '' then
MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['
Result := MapiSendMail(0,Handle ,MapiMessage,MAPI_DIALOG*O
MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
// use this if you don't want the dialog box to come up
//Result := MapiSendMail(0,Handle ,MapiMessage,0, 0);
for i1 := 0 to AttachCount-1 do begin
strDispose(Attachments[i1]
strDispose(Attachments[i1]
end;
if assigned(MapiMessage.lpszS
strDispose(MapiMessage.lps
if assigned(MapiMessage.lpszN
strDispose(MapiMessage.lps
if assigned(R[0].lpszAddress)
if assigned(R[0].lpszName) then strDispose(R[0].lpszName);
if assigned(R[1].lpszAddress)
if assigned(R[1].lpszName) then strDispose(R[1].lpszName);
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hey, where is stated "if you don't want to use the API", should be "... want to use Outlook"
Cheers,
Bruno
Cheers,
Bruno
ASKER
Thanks everybody for the pointers, jduncan for the code. I think Bruno's answer is what I am looking for though, as I did not want to install any other applications such as outlook to send the fax with.
Thanks again for your help
Goodangel
Thanks again for your help
Goodangel