Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Нашел в Инете- не хочет работать [D6, XP]


Marat ©   (2007-04-30 13:50:00) 

Начал разбираться с OutLookExpress. Хочу, чтобы можно было послать сформированный файл кому-нибудь на почту. Нашел в Инете:
uses
comobj;

procedure sendmail(subject, body, recvaddress : string; attachs : array of string);
var
mm, ms : variant;
i : integer;
begin
ms := createoleobject('msmapi.mapisession');
try
mm := createoleobject('msmapi.mapimessages');
try
ms.downloadmail := false;
ms.newsession := false;
ms.logonui := true;
ms.signon;
mm.sessionid := ms.sessionid;

mm.compose;

mm.recipindex := 0;
mm.recipaddress := recvaddress;
mm.msgsubject := subject;
mm.msgnotetext := body;

for i := low(attachs) to high(attachs) do
begin
mm.attachmentindex := i;
mm.attachmentpathname := attachs[i];
end;
mm.send(true);
ms.signoff;
finally
varclear(ms);
end;
finally
varclear(mm);
end;
end;

procedure tform1.formcreate(sender : tobject);
begin
sendmail('subject', 'body'#13#10'second', 'billgates@microsoft.com',
['c:winntexplorer.exe', 'c:winntwin.ini']);
end;

попробовал запустить, а в строке "ms := createoleobject('msmapi.mapisession');" выдается ошибка "Недопустимая строка с указанием класса".
Как с этим бороться?


turbouser   (2007-04-30 15:25:00) [1]


> Marat ©   (30.04.07 14:26) [4]

Сам же написАл про OE :)
Без него - см. Indy.
Вот например:

uses idSMTP, idMessage, IdCharsets, IdAttachment;
procedure SendMail(Recipients_: string; subj: string = '');
var
 MessageSend: TidMessage;
 SMTP: TidSMTP;
begin
 SMTP := TidSMTP.Create;
 MessageSend := TidMessage.Create(nil);
 try
   SMTP.Host     := 'адрес сервера';
   SMTP.Port     := 25;
   SMTP.Username := 'имя пользователя';
   SMTP.Password := 'пароль';
   SMTP.Connect;
   with MessageSend do
   begin
     charset     := IdCharsetNames[idcswindows_1251];
     contentType := 'text/plain';
     From.Text   := 'user@server.ru';
     ReplyTo.EMailAddresses := 'user@server.ru';
     Recipients.EMailAddresses := Recipients_;
     Subject     := 'Сабж';
     Body.Add('Строка 1');
     Body.Add('Строка 2');
     Priority := TIdMessagePriority(mpHighest);
     CCList.EMailAddresses := 'user@server.ru';
     BccList.EMailAddresses := 'user@server.ru';
     ReceiptRecipient.Text := Recipients_;
   end;
   SMTP.Send(MessageSend);
   try
     SMTP.Disconnect;
   except
   end;
 finally
   SMTP.Free;
   MessageSend.Free;
 end;
end;


Marat   (2007-04-30 14:26:00) [2]

А нельзя, чтобы он сам отправил без окна OutLookExpress?


turbouser   (2007-04-30 14:12:00) [3]

SendMail('от_кого@откуда.ru', 'кому@куда.ru','Сабж', 'Текст'#13#10'сообщения', 'c:\autoexec.bat', True);


Marat   (2007-04-30 14:06:00) [4]

А можно пример запуска функции SendMail(const From, Dest, Subject, Text, FileName: PAnsiChar; Outlook: boolean): integer;?


turbouser   (2007-04-30 13:58:00) [5]


uses MAPI;
function SendMail(const From, Dest, Subject, Text, FileName: PAnsiChar; Outlook: boolean): integer;
var
 Message: TMapiMessage;
 Recipient, Sender: TMapiRecipDesc;
 File_Attachment: TMapiFileDesc;

 function MakeMessage: TMapiMessage;
 begin
   FillChar(Sender, SizeOf(Sender), 0);
   Sender.ulRecipClass := MAPI_ORIG;
   Sender.lpszAddress  := From;

   FillChar(Recipient, SizeOf(Recipient), 0);
   Recipient.ulRecipClass := MAPI_TO;
   Recipient.lpszAddress  := Dest;

   FillChar(File_Attachment, SizeOf(File_Attachment), 0);
   File_Attachment.nPosition    := cardinal(-1);
   File_Attachment.lpszPathName := FileName;

   FillChar(Result, SizeOf(Result), 0);
   with Message do
   begin
     lpszSubject  := Subject;
     lpszNoteText := Text;
     lpOriginator := @Sender;
     nRecipCount  := 1;
     lpRecips     := @Recipient;
     nFileCount   := 1;
     lpFiles      := @File_Attachment;
   end;
 end;

var
 SM: TFNMapiSendMail;
 MAPIModule: HModule;
 MAPI_FLAG: cardinal;
begin
 if Outlook then
   MAPI_FLAG := MAPI_DIALOG
 else
   MAPI_FLAG := 0;
 MAPIModule := LoadLibrary(PChar(MAPIDLL));
 if MAPIModule = 0 then
   Result := -1
 else
   try
     @SM := GetProcAddress(MAPIModule, 'MAPISendMail');
     if @SM <> nil then
     begin
       MakeMessage;
       Result := SM(0, Application.Handle, Message, MAPI_FLAG, 0);
     end
     else
       Result := 1;
   finally
     FreeLibrary(MAPIModule);
   end;
end;


Наверх

Титульная страница Поиск, карта сайта Написать письмо