Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.05.13;
Скачать: CL | DM;

Вниз

Как вложить в почтовое сообщение несколько файлов?   Найти похожие ветки 

 
Fin ©   (2007-02-09 11:24) [0]

Добрый день! Вопосо собственно в теме. Скажу толко что когда на входе подовал не массив имен файлов а только один путь и Attach обьявлял не как массив, то всё работает, но мне нужно именно отправит несколько файлов.
Подскажите что делаю не так?

Function MSend(Email:string;NameFile: array of string;CountFile:integer;Tema:string; TeloMail:string):integer;
var
   MapiMessage: TMapiMessage;
   AdressTo   : TMapiRecipDesc;
   Attach     : array of TMapiFileDesc;
   MError: Cardinal;
   i:integer;
begin
SetLength(Attach,CountFile);
for i:=0 to CountFile-1 do
begin

Attach[i].ulReserved              := 0;
Attach[i].flFlags                 := MAPI_OLE_STATIC;
Attach[i].nPosition               := 0;
Attach[i].lpFileType              := nil;
Attach[i].lpszPathName            :=@NameFile[i];
Attach[i].lpszFileName            := nil;
end;

AdressTo.ulReserved            := 0;
AdressTo.lpszName              := @Email[1];
AdressTo.lpszAddress           := @Email[1];
AdressTo.ulRecipClass          := MAPI_TO;
AdressTo.ulEIDSize             := 0;
AdressTo.lpEntryID             := nil;

MapiMessage.ulReserved         := 0;
MapiMessage.lpszSubject        := @Tema[1];
MapiMessage.lpszNoteText       := @TeloMail[1];
MapiMessage.lpszMessageType    := nil;
MapiMessage.lpszDateReceived   := nil;
MapiMessage.lpszConversationID := nil;
MapiMessage.flFlags            := 0;
MapiMessage.lpOriginator       := nil;
MapiMessage.nRecipCount        := 1;
MapiMessage.lpRecips           := @AdressTo;
MapiMessage.nFileCount         := CountFile;
MapiMessage.lpFiles            := @Attach;

MError := MapiSendMail(0, 0, MapiMessage, MAPI_LOGON_UI, 0);
   if MError <> 0 then result:=MError
                  else result:=0;
end;


 
clickmaker ©   (2007-02-09 11:39) [1]


>  Fin ©   (09.02.07 11:24)

а какая MError?


 
Fin ©   (2007-02-09 11:43) [2]

2


 
Fin ©   (2007-02-09 12:16) [3]

MAPI_E_FAILURE = 2;


 
clickmaker ©   (2007-02-09 12:21) [4]


> Attach[i].flFlags                 := MAPI_OLE_STATIC

а вот это зачем? попробуй := 0


 
Fin ©   (2007-02-09 12:28) [5]

пробовал и 0 и MAPI_OLE всё одно. А почему MAPI_OLE_STATIC - просто когда отправлял файлы по одиночке поставил так и всё работало.


 
clickmaker ©   (2007-02-09 12:32) [6]


> Attach[i].nPosition               := 0;

Mapi Help

nPosition

Integer used to indicate where in the message body to render the attachment. Attachments replace the character found at a certain position in the message body. That is, attachments replace character in the MapiMessage structure field lpszNoteText[nPosition]. A value of  - 1 (0xFFFFFFFF) means attachment position is not indicated; the application will have to provide a way for the user to access the attachment.

?


 
Fin ©   (2007-02-09 13:00) [7]

на самом деле у меня там стоит Attach[i].nPosition:= i+1; это я просто проверял и по ошибке не изменил.


 
fd979 ©   (2007-02-09 21:16) [8]

Я пользуюсь вот этим, но как понимаете это для MS Outlook:

function SendEmailGen (Recipients, Attachments : TStringList; SubjectStr: String; BodyStr: TStrings) : Boolean;
const
 olMailItem = 0;
 olAppointmentItem = 1;
 olContactItem = 2;
 olTaskItem  = 3;
 olJournalItem = 4;
 olNoteItem = 5;
 olPostItem = 6;
 olByValue = 1;
 olByReference = 4;
 olEmbeddedItem = 5;
 olOLE = 6;
var
 myOlApp, myItem, myRecipient, myAttachments: OleVariant;
 I  : Integer;
begin
 myOlApp := CreateOLEObject("Outlook.Application");
 myItem := myOlApp.CreateItem(olMailItem);

 myItem.Subject := SubjectStr;

 for i := 0 to Recipients.Count - 1 do
   myRecipient := myItem.Recipients.Add(Recipients.Strings[i]);
 myItem.Body := BodyStr.Text;

 myAttachments := myItem.Attachments;
 if Attachments <> nil then
 for i := 0 to Attachments.Count - 1 do
   myAttachments.Add(Attachments.Strings[i], olByValue, 1, " ");

 myItem.Send;
 myOlApp := VarNull;
 myItem := VarNull;
 myRecipient := VarNull;
 myAttachments := VarNull;
 Result := True;
end;


 
Fin ©   (2007-02-09 22:27) [9]

К сожалению не пойдёт. Не могу привязыватся к конкретному клиенту.


 
Fin ©   (2007-02-11 01:19) [10]

Всё ни как не могу победить, судя по всему загвоздка тут
MapiMessage.lpFiles            := @Attach; при условии что @Attach массив целиком, так как если MapiMessage.lpFiles            := @Attach[0] всё успешно работает (вместо 0 любой другой существующий индекс тоже проходит)
?????????????????
Натолкните на мысль.


 
clickmaker ©   (2007-02-12 10:22) [11]

вот эта строчка смущает
Attach[i].lpszPathName := @NameFile[i];
по идее, так там должен быть мусор

напиши так
Attach[i].ulReserved := 0;
Attach[i].flFlags := 0;
Attach[i].nPosition := Cardinal(-1);
Attach[i].lpFileType := nil;
Attach[i].lpszPathName := pchar(NameFile[i]); // или @NameFile[i][1]
Attach[i].lpszFileName := nil;


 
Fin ©   (2007-02-13 08:09) [12]

clickmaker  спасибо за то что пытаешься помочь, но эту ошибку я уже исправил,

Attach[i].ulReserved              := 0;
Attach[i].flFlags                    := 0;
Attach[i].nPosition                 := Cardinal(-1);//1;//ULONG(-1);
Attach[i].lpFileType               := nil;
Attach[i].lpszPathName          :=StrNew(PChar(NameFile[i]) );
Attach[i].lpszFileName            :=StrNew(PChar(extractfilename(NameFile[i])));

там действительно был мусор. Но по прежнему ошибка №2. В принципе в инете нашол много других алгоритмов отправки, но через либо indy и др.
Но ужасть как хочется разобраться в чём же тут загвоздка. Ещё раз спасибо за терепение и приму любую помощь в поиске ошибки!


 
Fin ©   (2007-02-13 08:24) [13]

Попробовал скормить тут MapiMessage.lpFiles            := @Attach; при этом @Attach - массив, но пустой, всё прошло успешно, скорее что то не так записываю в массив????


 
Fin ©   (2007-02-13 14:30) [14]

Рабочий вариант

Function MSend(Email:string;NameFile: array of string;CountFile:integer;Tema:string; TeloMail:string):integer;
var
   MapiMessage: TMapiMessage;
   AdressTo   : TMapiRecipDesc;
   Pfil, Attach      :  PMapiFileDesc;
   MError: Cardinal;
   i:integer;
begin

GetMem(Attach,sizeof(TMapiFileDesc)*CountFile);
Pfil:=Attach ;
for i:=0 to CountFile-1 do
begin

Attach^.ulReserved              := 0;
Attach^.flFlags                 := 0;
Attach^.nPosition               := Cardinal(-1);
Attach^.lpFileType              := nil;
Attach^.lpszPathName            :=StrNew(PChar(NameFile[i]) );
Attach^.lpszFileName            :=StrNew(PChar(extractfilename(NameFile[i])));
inc(Attach);
end;

AdressTo.ulReserved            := 0;
AdressTo.lpszName              := @Email[1];
AdressTo.lpszAddress           := @Email[1];
AdressTo.ulRecipClass          := MAPI_TO;
AdressTo.ulEIDSize             := 0;
AdressTo.lpEntryID             := nil;

MapiMessage.ulReserved         := 0;
MapiMessage.lpszSubject        := @Tema[1];
MapiMessage.lpszNoteText       := @TeloMail[1];
MapiMessage.lpszMessageType    := nil;
MapiMessage.lpszDateReceived   := nil;
MapiMessage.lpszConversationID := nil;
MapiMessage.flFlags            := 0;
MapiMessage.lpOriginator       := nil;
MapiMessage.nRecipCount        := 1;
MapiMessage.lpRecips           := @AdressTo;
MapiMessage.nFileCount         := CountFile;
MapiMessage.lpFiles            := Pfil;

MError := MapiSendMail(0, 0, MapiMessage, MAPI_LOGON_UI, 0);
//FreeMem( Attach);
   if MError <> 0 then result:=MError
                  else result:=0;
end;


 
Fin ©   (2007-03-14 11:40) [15]

Доброго времени суток.
Дабы не плодить темы задам вопрос тут. К тому же вопрос "схожий".

Не могу заставить что бы отпровляемое сообщение требовало подтверждение о прочтении.

В свою очередь я для этого пытаюсь предеть парметру MapiMessage.flFlags значение MAPI_RECEIPT_REQUESTED. и не чего не выходит (подтвержение не просит). Как поступить?
Наведите на мысль!



Страницы: 1 вся ветка

Текущий архив: 2007.05.13;
Скачать: CL | DM;

Наверх




Память: 0.51 MB
Время: 0.036 c
11-1156803696
AndreyRus
2006-08-29 02:21
2007.05.13
Memo с гипертекстом


2-1177036858
ArchValentin
2007-04-20 06:40
2007.05.13
Создание прокси-серверов


2-1176971322
Lewka
2007-04-19 12:28
2007.05.13
работа с базой данных Access


2-1177403993
Neket
2007-04-24 12:39
2007.05.13
Сравнить строки в Excel


2-1177487406
Neket
2007-04-25 11:50
2007.05.13
Скопировать строки в Excel