Mapi.pas para envio de e-mail.
16/08/2004
0
boa tarde pessoal, blz ? ....
estou usando a seguinte função para mandar email pelo delphi usando a biblioteca mapi (a função abre o outlook express para o envio):
function Tf_geral.EnviaMail(hWnd: Integer; const Destinatario, Assunto, Body, Anexo: PChar): WordBool; stdcall; export;
var
MapiMessage: TMapiMessage;
MError: Cardinal;
Sender: TMapiRecipDesc;
PRecip, Recipients: PMapiRecipDesc;
PFiles, Attachments: PMapiFileDesc;
begin
Result := False;
Application.Handle := hWnd;
MapiMessage.nRecipCount := 1;
GetMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc));
try
with MapiMessage do
begin
ulReserved := 0;
lpszSubject := Assunto;
lpszNoteText := PChar(Body);
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;
flFlags := 0;
Sender.ulReserved := 0;
Sender.ulRecipClass := MAPI_ORIG;
Sender.lpszName := PChar(´´);
Sender.lpszAddress := PChar(´´);
Sender.ulEIDSize := 0;
Sender.lpEntryID := nil;
lpOriginator := @Sender;
PRecip := Recipients;
PRecip^.ulReserved := 0;
PRecip^.ulRecipClass := MAPI_TO;
PRecip^.lpszName := Destinatario;
PRecip^.lpszAddress := StrNew(PChar(´SMTP:´ + Destinatario));
PRecip^.ulEIDSize := 0;
PRecip^.lpEntryID := nil;
Inc(PRecip);
lpRecips := Recipients;
nFileCount := 1;
GetMem(Attachments, nFileCount * sizeof(TMapiFileDesc));
PFiles := Attachments;
Attachments^.lpszPathName := Anexo;
Attachments^.lpszFileName := PChar(ExtractFileName(Anexo));
Attachments^.ulReserved := 0;
Attachments^.flFlags := 0;
Attachments^.nPosition := Cardinal(-1);
Attachments^.lpFileType := nil;
Inc(Attachments);
lpFiles := PFiles;
end;
MError := MapiSendMail(0, hWnd, MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
case MError of
MAPI_E_USER_ABORT: MessageDlg(´Operação abortada pelo usuário´, mtInformation, [mbOk], 0);
SUCCESS_SUCCESS: Result := True;
else
MessageDlg(´Ocorreu um erro inesperado!´#13+´Código: ´ + IntToStr(MError), mtError, [mbOk], 0);
end;
finally
PRecip := Recipients;
StrDispose(PRecip^.lpszAddress);
Inc(PRecip);
FreeMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc));
if Assigned(PFiles) then
FreeMem(PFiles, MapiMessage.nFileCount * sizeof(TMapiFileDesc));
Application.Handle := 0;
end;
end;
a função funciona, porém as telas que eu tenho abertas em .showmodal perdem essa propriedade e ficam como se estivesse com apenas .show,
alguém sabe como resolver isso ? ou alguém tem alguma função que funcione com o outlook express ?
obrigado pela ajuda.
estou usando a seguinte função para mandar email pelo delphi usando a biblioteca mapi (a função abre o outlook express para o envio):
function Tf_geral.EnviaMail(hWnd: Integer; const Destinatario, Assunto, Body, Anexo: PChar): WordBool; stdcall; export;
var
MapiMessage: TMapiMessage;
MError: Cardinal;
Sender: TMapiRecipDesc;
PRecip, Recipients: PMapiRecipDesc;
PFiles, Attachments: PMapiFileDesc;
begin
Result := False;
Application.Handle := hWnd;
MapiMessage.nRecipCount := 1;
GetMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc));
try
with MapiMessage do
begin
ulReserved := 0;
lpszSubject := Assunto;
lpszNoteText := PChar(Body);
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;
flFlags := 0;
Sender.ulReserved := 0;
Sender.ulRecipClass := MAPI_ORIG;
Sender.lpszName := PChar(´´);
Sender.lpszAddress := PChar(´´);
Sender.ulEIDSize := 0;
Sender.lpEntryID := nil;
lpOriginator := @Sender;
PRecip := Recipients;
PRecip^.ulReserved := 0;
PRecip^.ulRecipClass := MAPI_TO;
PRecip^.lpszName := Destinatario;
PRecip^.lpszAddress := StrNew(PChar(´SMTP:´ + Destinatario));
PRecip^.ulEIDSize := 0;
PRecip^.lpEntryID := nil;
Inc(PRecip);
lpRecips := Recipients;
nFileCount := 1;
GetMem(Attachments, nFileCount * sizeof(TMapiFileDesc));
PFiles := Attachments;
Attachments^.lpszPathName := Anexo;
Attachments^.lpszFileName := PChar(ExtractFileName(Anexo));
Attachments^.ulReserved := 0;
Attachments^.flFlags := 0;
Attachments^.nPosition := Cardinal(-1);
Attachments^.lpFileType := nil;
Inc(Attachments);
lpFiles := PFiles;
end;
MError := MapiSendMail(0, hWnd, MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
case MError of
MAPI_E_USER_ABORT: MessageDlg(´Operação abortada pelo usuário´, mtInformation, [mbOk], 0);
SUCCESS_SUCCESS: Result := True;
else
MessageDlg(´Ocorreu um erro inesperado!´#13+´Código: ´ + IntToStr(MError), mtError, [mbOk], 0);
end;
finally
PRecip := Recipients;
StrDispose(PRecip^.lpszAddress);
Inc(PRecip);
FreeMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc));
if Assigned(PFiles) then
FreeMem(PFiles, MapiMessage.nFileCount * sizeof(TMapiFileDesc));
Application.Handle := 0;
end;
end;
a função funciona, porém as telas que eu tenho abertas em .showmodal perdem essa propriedade e ficam como se estivesse com apenas .show,
alguém sabe como resolver isso ? ou alguém tem alguma função que funcione com o outlook express ?
obrigado pela ajuda.
Augustoaf
Curtir tópico
+ 0
Responder
Posts
27/08/2004
Crmonari
no inicio da função
EnviaMail(hWnd: Integer ................
Use Applicattion.Handle
ai funciona
EnviaMail(hWnd: Integer ................
Use Applicattion.Handle
ai funciona
Responder
12/09/2005
O4pr3ndiz
Eu useis a funçao acima
function TForm1.EnviaMail(hWnd: Integer; const Destinatario, Assunto, Body, Anexo: PChar): WordBool; stdcall; export;
mas naum entendi como usar??
Tipo como declarar no evento on-click de um botao para usá-la? Como usa-lá com vários emails???
Eu naum qero anexo... como deveria fazer?
Alguem testou este código? ele funciona mesmo???
function TForm1.EnviaMail(hWnd: Integer; const Destinatario, Assunto, Body, Anexo: PChar): WordBool; stdcall; export;
mas naum entendi como usar??
Tipo como declarar no evento on-click de um botao para usá-la? Como usa-lá com vários emails???
Eu naum qero anexo... como deveria fazer?
Alguem testou este código? ele funciona mesmo???
Responder
Clique aqui para fazer login e interagir na Comunidade :)