|
Простейший пример посылки письма с аттачем в мапи без использвания
каких либо компонентов
RecipName - имя получателя
SendName - адрес отправителя
RecipAddress - адрес получателя
Subject - тема
Attachment - путь с именем к фаилу
unit email;
interface
uses Windows,Mapi;
function SendEmail(const RecipName,SendName, RecipAddress, Subject,
Attachment: string): Boolean;
implementation
function SendEmail(const RecipName, SendName, RecipAddress,
Subject, Attachment: string): Boolean;
var
MapiMessage: TMapiMessage; //основная структура сообщения
MapiFileDesc: TMapiFileDesc;//структура вложения
MapiRecipDesc,MapiSenderDesc: TMapiRecipDesc;//структура назначения
отправки
begin
with MapiRecipDesc do
begin
ulReserved:= 0;
ulRecipClass:= MAPI_TO;
lpszName:= PChar(RecipName);кому-имя
lpszAddress:= PChar(RecipAddress);//адресс для отправки
ulEIDSize:= 0;
lpEntryID:= nil;
end;
with MapiSenderDesc do
begin
ulRecipClass := MAPI_ORIG;
lpszAddress := SendName; //от кого
end;
with MapiFileDesc do
begin
ulReserved:= 0;
flFlags:= 0;
nPosition:= 0;
lpszPathName:= PChar(Attachment);//вложение
lpszFileName:= nil;
lpFileType:= nil;
end;
with MapiMessage do begin //создание письма
ulReserved := 0;
lpszSubject := nil;
lpszNoteText := PChar(Subject);//тема сабжа
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;
flFlags := 0;
lpOriginator :=@MapiSenderDesc;
nRecipCount := 1;
lpRecips := @MapiRecipDesc;
if length(Attachment) > 0 then begin
nFileCount:= 1;//пример вложения только для одного фаила
lpFiles := @MapiFileDesc;
end else begin
nFileCount:= 0;
lpFiles:= nil;
end;
end;
Result:= MapiSendMail(0, 0, MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI
or MAPI_NEW_SESSION, 0) = SUCCESS_SUCCESS; //отправка с выводом
результата
end;
end.
|