cincap
Messages postés460Date d'inscriptiondimanche 5 décembre 2004StatutMembreDernière intervention 6 avril 20092 25 juil. 2007 à 11:03
Bonjour à toutes et à tous,
@ yvessimon, j'ai trouvé ceci :
function SendMail(const Subject, Body, FileName,
SenderName, SenderEMail, RecipientName, RecipientEMail: string): Integer;
var
Message: TMapiMessage;
lpSender, lpRecipient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;
SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
FillChar(Message, SizeOf(Message), 0);
with Message do
begin
if (Subject <> '') then
lpszSubject := PChar(Subject);
if (Body <> '') then
lpszNoteText := PChar(Body);
if (SenderEmail <> '') then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (SenderName = '') then
lpSender.lpszName := PChar(SenderEMail)
else
lpSender.lpszName := PChar(SenderName);
lpSender.lpszAddress := PChar(SenderEmail);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID := nil;
lpOriginator := @lpSender;
end;
if (RecipientEmail <> '') then
begin
lpRecipient.ulRecipClass := MAPI_TO;
if (RecipientName = '') then
lpRecipient.lpszName := PChar(RecipientEMail)
else
lpRecipient.lpszName := PChar(RecipientName);
lpRecipient.lpszAddress := PChar(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);
MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule = 0 then
Result := -1
else
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM <> nil then
begin
Result := SM(0, Application.Handle, Message, MAPI_DIALOG or MAPI_LOGON_UI, 0);
end
else
Result := 1;
finally
FreeLibrary(MAPIModule);
end;
if Result <> 0 then
MessageDlg('Error! You have cancelled the e-mail sending process yet...', mtInformation,
[mbOK], 0);
end;
if Subject = '' then Error('Subject not defined');
if SenderAddress = '' then Error('Sender address not defined');
if Recipients = nil then Error('No recipients defined');
if Recipients.Count = 0 then Error('No recipients defined');
case MapiResult of
MAPI_E_AMBIGUOUS_RECIPIENT : MapiRes := 'A recipient matched more than one of the recipient descriptor structures and
MAPI_DIALOG was not set. No message was sent.';
MAPI_E_ATTACHMENT_NOT_FOUND : MapiRes := 'The specified attachment was not found. No message was sent.';
MAPI_E_ATTACHMENT_OPEN_FAILURE : MapiRes := 'The specified attachment could not be opened. No message was sent.';
MAPI_E_BAD_RECIPTYPE : MapiRes := 'The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC. No message was
sent.';
MAPI_E_FAILURE : MapiRes := 'One or more unspecified errors occurred. No message was sent.';
MAPI_E_INSUFFICIENT_MEMORY : MapiRes := 'There was insufficient memory to proceed. No message was sent.';
MAPI_E_INVALID_RECIPS : MapiRes := 'One or more recipients were invalid or did not resolve to any address.';
MAPI_E_LOGIN_FAILURE : MapiRes := 'There was no default logon, and the user failed to log on successfully when the
logon dialog box was displayed. No message was sent.';
MAPI_E_TEXT_TOO_LARGE : MapiRes := 'The text in the message was too large. No message was sent.';
MAPI_E_TOO_MANY_FILES : MapiRes := 'There were too many file attachments. No message was sent.';
MAPI_E_TOO_MANY_RECIPIENTS : MapiRes := 'There were too many recipients. No message was sent.';
MAPI_E_UNKNOWN_RECIPIENT : MapiRes := 'A recipient did not appear in the address list. No message was sent.';
MAPI_E_USER_ABORT : MapiRes := 'The user canceled one of the dialog boxes. No message was sent.';
SUCCESS_SUCCESS : MapiRes := 'The call succeeded and the message was sent.';
end;
finally
if pRecipients <> nil then
FreeMem(pRecipients);
if pAttachments <> nil then
FreeMem(pAttachments);