powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Delphi [игнор отключен] [закрыт для гостей] / отправка почты
12 сообщений из 12, страница 1 из 1
отправка почты
    #32184408
Vladimir_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Delphi3
Помогите пожалуйста решить задачку (желательно без сторонних компонент). Нужно на одной из удалённых машин отслеживать текущее состояние какого-либо процесса и по резулитатам теста отправлять по почте нормальное письмо о текущем состоянии. Я нашёл ShellExecute(0,'open', 'mailto:bebe@lala.ru', nil, nil, 1); - это вряд ли подойдёт или я наверное не понял как этим пользоваться.
...
Рейтинг: 0 / 0
отправка почты
    #32184419
Gold
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А что значит без сторонних компонент? Бери стандартные со страницы FastNet. Тав в хелпе кажись и примеры есть ...
...
Рейтинг: 0 / 0
отправка почты
    #32184424
Vladimir_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Что-то я не нахожу такой закладки
...
Рейтинг: 0 / 0
отправка почты
    #32184426
Фотография KirillovA
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
а делфя какая?
...
Рейтинг: 0 / 0
отправка почты
    #32184428
Vladimir_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
вроде первым делом указал: III
...
Рейтинг: 0 / 0
отправка почты
    #32184436
Фотография KirillovA
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
сорри - из башки вылетело пока писал )))
поставь
http://www.nevrona.com/Indy/download/index.html
вроде работала под треху ...
...
Рейтинг: 0 / 0
отправка почты
    #32184445
Rostyk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Нашел такое:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
  {Simple MAPI example. I just want to give
  the user the general understanding of how to send MAPI mail with an
  attachment. In the real world this program would have multiple To's,
  multiple CC's, multiple BCC's, and multiple Attachments. I did not add
  MAPI components, I just used what came with Delphi 4. I believe this code
  should work with Delphi 3, 4, and 5. Some of the ideas are also from
  Danny's TEmail component. Again, thank you Danny.
  You can do whatever you please with the code. Just let me know if it is
  useful.
  I wrote this code in a none efficient way to show the intricate details
  of sending MAPI mail.
  Note: This program only accepts one To, one CC, one BCC, and one
  attachment. I have to leave some things for you to experiment!
} 

 unit  sender;

 interface 

 uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, Buttons, mapi;

 type 
  TfrmMain =  class (TForm)
    lblTo: TLabel;
    lblCC: TLabel;
    lblBCC: TLabel;
    txtSubject: TEdit;
    moBody: TMemo;
    lblSubject: TLabel;
    btnOK: TBitBtn;
    btnCancel: TBitBtn;
    lblMessageBody: TLabel;
    lblAttachment: TLabel;
    statSend: TStatusBar;
    btnBrowse: TButton;
    txtTo: TEdit;
    txtCC: TEdit;
    txtBCC: TEdit;
    txtAttachment: TEdit;
    AttachmentDlg: TOpenDialog;
     procedure  btnOKClick(Sender: TObject);
     procedure  btnCancelClick(Sender: TObject);
     procedure  btnBrowseClick(Sender: TObject);
   private 
     { Private declarations } 
   public 
     { Public declarations } 
   end ;

 const 
  RECIP_MAX       = MaxInt  div  SizeOf(TMapiRecipDesc);
  ATTACH_MAX      = MaxInt  div  SizeOf(TMapiFileDesc);

 type 
   { array of structures for TO, CC, and BCC } 
  TRecipAccessArray     =  array  [ 0  .. (RECIP_MAX -  1 )]  of  TMapiRecipDesc;
  TlpRecipArray         = ^TRecipAccessArray;
   { array of structures for attachments } 
  TAttachAccessArray    =  array  [ 0  .. (ATTACH_MAX -  1 )]  of  TMapiFileDesc;
  TlpAttachArray        = ^TAttachAccessArray;

 var 
  frmMain: TfrmMain;
  lppMapiMessage: MapiMessage;  // main message info pointer 
  hSession: ULONG;
  lppMapiFileDesc: MapiFileDesc;  // attachment info pointer 
  flFlags: ULONG;
  lparrayRecips: TlpRecipArray;
  lppMapiRecipDesc: TMapiRecipDesc;  // recipient info pointer 
  lparrayAttachments: TlpAttachArray;


 implementation 

 {$R *.DFM} 

 procedure  TfrmMain.btnOKClick(Sender: TObject);
 var 
    err: ULONG;
    AnyStr: PChar;
    nAttachments,
    nRecipients: Cardinal;
 begin 
      { This routine is going to simply make sure
       that all information are properly entered
       subject, to, and message body } 
      if  (txtTo.Text <> '')  and  (txtSubject.Text <> '')  and 
        (moBody.Lines.Count >  0 )  then 
      begin 
          nAttachments :=  1 ;
          nRecipients :=  0 ;
           if  txtTo.Text <> ''  then 
             Inc(nRecipients);
           if  txtCC.Text <> ''  then 
             Inc(nRecipients);
           if  txtBCC.Text <> ''  then 
             Inc(nRecipients);

           { assign 0 to all structure options } 
          FillChar(lppMapiRecipDesc, SizeOf(TMapiRecipDesc),  0 );
          lparrayRecips  := TlpRecipArray(StrAlloc(nRecipients*SizeOf(TMapiRecipDesc)));
          FillChar(lparrayRecips^, StrBufSize(PChar(lparrayRecips)),  0 );
          lparrayAttachments := TlpAttachArray(StrAlloc(nAttachments*SizeOf(TMapiFileDesc)));
          FillChar(lparrayAttachments^, StrBufSize(PChar(lparrayAttachments)),  0 );

           { check to see if there is file to attach } 

           if  txtAttachment.Text <> ''  then 
           begin 
           { info about Attachment} 
               lparrayAttachments^[ 0 ].ulReserved :=  0 ;
               lparrayAttachments^[ 0 ].flFlags :=  0 ;
               lparrayAttachments^[ 0 ].nPosition := ULONG($FFFFFFFF);
               AnyStr := StrAlloc(length(txtAttachment.Text)+ 1 );
               StrPCopy(AnyStr,txtAttachment.Text);
               lparrayAttachments^[ 0 ].lpszPathName := AnyStr;
               AnyStr :=  nil ;
               StrDispose(AnyStr);
               AnyStr := StrAlloc(length(ExtractFileName(txtAttachment.Text))+ 1 );
               StrPCopy(AnyStr,ExtractFileName(txtAttachment.Text));
               lparrayAttachments^[ 0 ].lpszFileName := AnyStr;
               AnyStr :=  nil ;
               StrDispose(AnyStr);
               lparrayAttachments^[ 0 ].lpFileType :=  nil ;
           end ;
          
           { info about recipient } 
          lparrayRecips^[ 0 ].ulReserved :=  0 ;
          lparrayRecips^[ 0 ].ulRecipClass := MAPI_TO;
          AnyStr := StrAlloc(length(txtTo.Text)+ 1 );
          StrPCopy(AnyStr,txtTo.Text);
          lparrayRecips^[ 0 ].lpszName := AnyStr;
          lparrayRecips^[ 0 ].lpszAddress :=  nil ;
          lparrayRecips^[ 0 ].ulEIDSize :=  0 ;
          lparrayRecips^[ 0 ].lpEntryID :=  nil ;
          AnyStr :=  nil ;
          StrDispose(AnyStr);

           { info about CC } 
           if  txtCC.Text <> ''  then 
           begin 
               AnyStr := StrAlloc(length(txtCC.Text)+ 1 );
               StrPCopy(AnyStr,txtCC.Text);
               lparrayRecips^.ulReserved :=  0 ;
               lparrayRecips^.ulRecipClass := MAPI_CC;
               lparrayRecips^.lpszName := AnyStr;
               lparrayRecips^.lpszAddress :=  nil ;
               lparrayRecips^.ulEIDSize :=  0 ;
               lparrayRecips^.lpEntryID :=  nil ;
               AnyStr :=  nil ;
               StrDispose(AnyStr);
           end ;

           { info about BCC } 
           if  txtBCC.Text <> ''  then 
           begin 
               AnyStr := StrAlloc(length(txtBCC.Text)+ 1 );
               StrPCopy(AnyStr,txtBCC.Text);
               lparrayRecips^.ulReserved :=  0 ;
               lparrayRecips^.ulRecipClass := MAPI_BCC;
               lparrayRecips^.lpszName := AnyStr;
               lparrayRecips^.lpszAddress :=  nil ;
               lparrayRecips^.ulEIDSize :=  0 ;
               lparrayRecips^.lpEntryID :=  nil ;
               AnyStr :=  nil ;
               StrDispose(AnyStr);
           end ;

           { main structure that is used to send the message } 
          lppMapiMessage.ulReserved := ULONG( 0 );
          lppMapiMessage.lpszSubject := PChar(txtSubject.Text);
          lppMapiMessage.lpszNoteText := PChar(moBody.Lines.Text);
          lppMapiMessage.lpszMessageType :=  nil ;
          lppMapiMessage.lpszDateReceived :=  nil ;
          lppMapiMessage.lpszConversationID :=  nil ;
          lppMapiMessage.flFlags := ULONG( 0 );
          lppMapiMessage.lpOriginator :=  nil ;
          lppMapiMessage.nRecipCount := nRecipients;
          lppMapiMessage.lpRecips := @lparrayRecips^;
          lppMapiMessage.nFileCount := nAttachments;
          lppMapiMessage.lpFiles := @lparrayAttachments^;
           { drops the mail in the outbox
            Make sure you check the option to send mail
            immediately in your Exchange or Outlook } 
          err := MAPISendMail( 0 , 0 ,lppMapiMessage, 0 , 0 );
           if  err <> SUCCESS_SUCCESS  then 
             ShowMessage('Error');
      end ;
 end ;

 procedure  TfrmMain.btnCancelClick(Sender: TObject);
 begin 
     Close;
 end ;

 procedure  TfrmMain.btnBrowseClick(Sender: TObject);
 begin 
     txtAttachment.Text := '';
      if  AttachmentDlg.Execute  then 
        txtAttachment.Text := AttachmentDlg.FileName;
 end ;

 end .
...
Рейтинг: 0 / 0
отправка почты
    #32184454
Vladimir_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Спасибо. Сейчас попробую.
...
Рейтинг: 0 / 0
отправка почты
    #32184520
Vladimir_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
УРА!!! Спасибо. всё просто замечательно.
Но есть одно но. В момент отправки появляется окошко с сообщением о том, что прграмма пытается что-то отправить с вашего компьютера. Типа возможен вирус. Требует подтвердить или отменить отправку. При этом по умолчанию - не отправлять. Можно это как-то побороть.
...
Рейтинг: 0 / 0
отправка почты
    #32184552
Rostyk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Outllok Express 6:
Сервис->Параметры->Безопасность->Защита от вирусов->Предупреждать, если приложения пытаются отправить почту от моего имени.
Этот параметр, наверное, скрывается в реестре.
Как это сделать других почтовых клиентах - не знаю.
...
Рейтинг: 0 / 0
отправка почты
    #32184681
Фотография KirillovA
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
на вот еще - работает идиально:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
unit MapiControl;

interface
{
Changelog:
 13 . 04 . 2001  Fixed memory Leak and String problem in adresses (Sendmail - method)
 31 . 08 . 2000  Some Changes on the TStrings Objects, added SetXXAdr-Methods
}
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; 

type 
  { Introducing a new Type of Event to get the Errorcode } 
  TMapiErrEvent = procedure(Sender: TObject; ErrCode: Integer) of object; 

  TMapiControl = class(TComponent) 
    constructor Create(AOwner: TComponent); override; 
    destructor Destroy; override; 
  private 
    { Private-Deklarationen } 
    FSubject: string; 
    FMailtext: string; 
    FFromName: string; 
    FFromAdress: string; 
    FTOAdr: TStrings; 
    FCCAdr: TStrings; 
    FBCCAdr: TStrings; 
    FAttachedFileName: TStrings; 
    FDisplayFileName: TStrings; 
    FShowDialog: Boolean; 
    FUseAppHandle: Boolean; 
    { Error Events: } 
    FOnUserAbort: TNotifyEvent; 
    FOnMapiError: TMapiErrEvent; 
    FOnSuccess: TNotifyEvent; 
    { +> Changes by Eugene Mayevski [mailto:Mayevski@eldos.org]} 
    procedure SetToAddr(newValue: TStrings); 
    procedure SetCCAddr(newValue: TStrings); 
    procedure SetBCCAddr(newValue: TStrings); 
    procedure SetAttachedFileName(newValue: TStrings); 
    { +< Changes } 
  protected 
    { Protected-Deklarationen } 
  public 
    { Public-Deklarationen } 
    ApplicationHandle: THandle; 
    procedure Sendmail(); 
    procedure Reset(); 
  published 
    { Published-Deklarationen } 
    property Subject: string read FSubject write FSubject; 
    property Body: string read FMailText write FMailText; 
    property FromName: string read FFromName write FFromName; 
    property FromAdress: string read FFromAdress write FFromAdress; 
    property Recipients: TStrings read FTOAdr write SetTOAddr; 
    property CopyTo: TStrings read FCCAdr write SetCCAddr; 
    property BlindCopyTo: TStrings read FBCCAdr write SetBCCAddr; 
    property AttachedFiles: TStrings read FAttachedFileName write SetAttachedFileName; 
    property DisplayFileName: TStrings read FDisplayFileName; 
    property ShowDialog: Boolean read FShowDialog write FShowDialog; 
    property UseAppHandle: Boolean read FUseAppHandle write FUseAppHandle; 

    { Events: } 
    property OnUserAbort: TNotifyEvent read FOnUserAbort write FOnUserAbort; 
    property OnMapiError: TMapiErrEvent read FOnMapiError write FOnMapiError; 
    property OnSuccess: TNotifyEvent read FOnSuccess write FOnSuccess; 
  end; 

procedure Register; 

implementation 

uses Mapi; 

{ Register the component: } 

procedure Register; 
begin 
  RegisterComponents('expectIT', [TMapiControl]); 
end; 

{ TMapiControl } 

constructor TMapiControl.Create(AOwner: TComponent); 
begin 
  inherited Create(AOwner); 
  FOnUserAbort := nil; 
  FOnMapiError := nil; 
  FOnSuccess := nil; 
  FSubject := ''; 
  FMailtext := ''; 
  FFromName := ''; 
  FFromAdress := ''; 
  FTOAdr := TStringList.Create; 
  FCCAdr := TStringList.Create; 
  FBCCAdr := TStringList.Create; 
  FAttachedFileName := TStringList.Create; 
  FDisplayFileName := TStringList.Create; 
  FShowDialog := False; 
  ApplicationHandle := Application.Handle; 
end; 

{ +> Changes by Eugene Mayevski [mailto:Mayevski@eldos.org]} 

procedure TMapiControl.SetToAddr(newValue: TStrings); 
begin 
  FToAdr.Assign(newValue); 
end; 

procedure TMapiControl.SetCCAddr(newValue: TStrings); 
begin 
  FCCAdr.Assign(newValue); 
end; 

procedure TMapiControl.SetBCCAddr(newValue: TStrings); 
begin 
  FBCCAdr.Assign(newValue); 
end; 

procedure TMapiControl.SetAttachedFileName(newValue: TStrings); 
begin 
  FAttachedFileName.Assign(newValue); 
end; 
{ +< Changes } 

destructor TMapiControl.Destroy; 
begin 
  FTOAdr.Free; 
  FCCAdr.Free; 
  FBCCAdr.Free; 
  FAttachedFileName.Free; 
  FDisplayFileName.Free; 
  inherited destroy; 
end; 

{ Reset the fields for re-use} 

procedure TMapiControl.Reset; 
begin 
  FSubject := ''; 
  FMailtext := ''; 
  FFromName := ''; 
  FFromAdress := ''; 
  FTOAdr.Clear; 
  FCCAdr.Clear; 
  FBCCAdr.Clear; 
  FAttachedFileName.Clear; 
  FDisplayFileName.Clear; 
end; 

{ Send the Mail via the API, this procedure composes and sends 
  the Email } 

procedure TMapiControl.Sendmail; 
var 
  MapiMessage: TMapiMessage; 
  MError: Cardinal; 
  Sender: TMapiRecipDesc; 
  PRecip, Recipients: PMapiRecipDesc; 
  PFiles, Attachments: PMapiFileDesc; 
  i: Integer; 
  AppHandle: THandle; 
begin 
  { First we store the Application Handle, if not 
    the Component might fail to send the Email or 
    your calling Program gets locked up. } 
  AppHandle := Application.Handle; 

  { Initialize the Attachment Pointer, to keep Delphi quiet } 
  PFiles := nil; 

  { We need all recipients to alloc the memory } 
  MapiMessage.nRecipCount := FTOAdr.Count + FCCAdr.Count + FBCCAdr.Count; 
  GetMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc)); 

  try 
    with MapiMessage do 
      begin 
        ulReserved :=  0 ; 
        { Setting the Subject: } 
        lpszSubject := PChar(Self.FSubject); 

        { ... the Body: } 
        lpszNoteText := PChar(FMailText); 

        lpszMessageType := nil; 
        lpszDateReceived := nil; 
        lpszConversationID := nil; 
        flFlags :=  0 ; 

        { and the sender: (MAPI_ORIG) } 
        Sender.ulReserved :=  0 ; 
        Sender.ulRecipClass := MAPI_ORIG; 
        Sender.lpszName := PChar(FromName); 
        Sender.lpszAddress := PChar(FromAdress); 
        Sender.ulEIDSize :=  0 ; 
        Sender.lpEntryID := nil; 
        lpOriginator := @Sender; 

        PRecip := Recipients; 

        { We have multiple recipients: (MAPI_TO) 
          and setting up each: } 
        if nRecipCount >  0  then 
          begin 
            for i :=  1  to FTOAdr.Count do 
              begin 
                PRecip^.ulReserved :=  0 ; 
                PRecip^.ulRecipClass := MAPI_TO; 
                { lpszName should carry the Name like in the 
                  contacts or the adress book, I will take the 
                  email adress to keep it short: } 
                PRecip^.lpszName := PChar(FTOAdr.Strings[i -  1 ]); 
                { If you use this component with Outlook97 or  2000  
                  and not some of Express versions you will have to set 
                  'SMTP:' in front of each (email-) adress. Otherwise 
                  Outlook/Mapi will try to handle the Email on itself. 
                  Sounds strange, just erease the 'SMTP:', compile, compose 
                  a mail and take a look at the resulting email adresses 
                  (right click). 
                } 
                { +> Changes by Andreas Hoerig [mailto:andreas.hoerig@sillner.com] } 
                PRecip^.lpszAddress := StrNew(PChar('SMTP:' + FTOAdr.Strings[i -  1 ])); 
                { +< Changes  } 
                PRecip^.ulEIDSize :=  0 ; 
                PRecip^.lpEntryID := nil; 
                Inc(PRecip); 
              end; 

            { Same with the carbon copy recipients: (CC, MAPI_CC) } 
            for i :=  1  to FCCAdr.Count do 
              begin 
                PRecip^.ulReserved :=  0 ; 
                PRecip^.ulRecipClass := MAPI_CC; 
                PRecip^.lpszName := PChar(FCCAdr.Strings[i -  1 ]); 
                { +> Changes by Andreas Hoerig [mailto:andreas.hoerig@sillner.com] } 
                PRecip^.lpszAddress := StrNew(PChar('SMTP:' + FCCAdr.Strings[i -  1 ])); 
                { +< Changes  } 
                PRecip^.ulEIDSize :=  0 ; 
                PRecip^.lpEntryID := nil; 
                Inc(PRecip); 
              end; 

            { ... and the blind copy recipients: (BCC, MAPI_BCC) } 
            for i :=  1  to FBCCAdr.Count do 
              begin 
                PRecip^.ulReserved :=  0 ; 
                PRecip^.ulRecipClass := MAPI_BCC; 
                PRecip^.lpszName := PChar(FBCCAdr.Strings[i -  1 ]); 
                { +> Changes by Andreas Hoerig [mailto:andreas.hoerig@sillner.com] } 
                PRecip^.lpszAddress := StrNew(PChar('SMTP:' + FBCCAdr.Strings[i -  1 ])); 
                { +< Changes  } 
                PRecip^.ulEIDSize :=  0 ; 
                PRecip^.lpEntryID := nil; 
                Inc(PRecip); 
              end; 
          end; 
        lpRecips := Recipients; 

        { Now we process the attachments: } 
        nFileCount := FAttachedFileName.Count; 
        if nFileCount >  0  then 
          begin 
            GetMem(Attachments, nFileCount * sizeof(TMapiFileDesc)); 
            PFiles := Attachments; 

            { Fist setting up the display names (without path): } 
            FDisplayFileName.Clear; 
            for i :=  1  to FAttachedFileName.Count do 
              FDisplayFileName.Add(ExtractFileName(FAttachedFileName[i -  1 ])); 

            if nFileCount >  0  then 
              begin 
                { Now we pass the attached file (their paths) to the
                  structure: } 
                for i :=  1  to FAttachedFileName.Count do 
                  begin 
                    { Setting the complete Path } 
                    Attachments^.lpszPathName := PChar(FAttachedFileName.Strings[i -  1 ]); 
                    { ... and the displayname: } 
                    Attachments^.lpszFileName := PChar(FDisplayFileName.Strings[i -  1 ]); 
                    Attachments^.ulReserved :=  0 ; 
                    Attachments^.flFlags :=  0 ; 
                    { Position has to be - 1 , please see the WinApi Help 
                      for details. } 
                    Attachments^.nPosition := Cardinal(- 1 ); 
                    Attachments^.lpFileType := nil; 
                    Inc(Attachments); 
                  end; 
              end; 
            lpFiles := PFiles; 
          end 
        else 
          begin 
            nFileCount :=  0 ; 
            lpFiles := nil; 
          end; 
      end; 

    { Send the Mail, silent or verbose: 
      Verbose means in Express a Mail is composed and shown as setup. 
      In non-Express versions we show the Login-Dialog for a new 
      session and after we have choosen the profile to use, the 
      composed email is shown before sending 

      Silent does currently not work for non-Express version. We have 
      no Session, no Login Dialog so the system refuses to compose a 
      new email. In Express Versions the email is sent in the
      background. 

      Please Note: It seems that your success on the delivery depends 
      on a combination of MAPI-Flags (MAPI_DIALOG, MAPI_LOGON_UI, ...) 
      and your used OS and Office Version. I am currently using 
      Win2K SP1 and Office 2K SP2 with no problems at all. 
      If you experience problems on another versions, please try 
      a different combination of flags for each purpose (Dialog or not). 
      I would be glad to setup a table with working flags on 
      each OS/Office combination, just drop me a line. 

      Possible combinations are also (with Dialog): 
       1 . MAPI_DIALOG or MAPI_LOGON_UI MAPI_NEW_SESSION or MAPI_USE_DEFAULT 
       2 . MAPI_SIMPLE_DEFAULT 

      See MAPI.PAS or MAPI.H (SDK) for more... 
     } 
    if FShowDialog then 
      MError := MapiSendMail( 0 , AppHandle, MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION,  0 )
    else
      MError := MapiSendMail( 0 , AppHandle, MapiMessage,  0 ,  0 ); 

    { Now we have to process the error messages. There are some 
      defined in the MAPI unit please take a look at the unit to get 
      familiar with it. 
      I decided to handle USER_ABORT and SUCCESS as special and leave 
      the rest to fire the  "new"  error event defined at the top (as 
      generic error) 

      Not treated as special (constants from mapi.pas): 

      MAPI_E_FAILURE =  2 ; 
      MAPI_E_LOGON_FAILURE =  3 ; 
      MAPI_E_LOGIN_FAILURE = MAPI_E_LOGON_FAILURE;
      MAPI_E_DISK_FULL =  4 ; 
      MAPI_E_INSUFFICIENT_MEMORY =  5 ; 
      MAPI_E_ACCESS_DENIED =  6 ; 
      MAPI_E_TOO_MANY_SESSIONS =  8 ; 
      MAPI_E_TOO_MANY_FILES =  9 ; 
      MAPI_E_TOO_MANY_RECIPIENTS =  10 ; 
      MAPI_E_ATTACHMENT_NOT_FOUND =  11 ; 
      MAPI_E_ATTACHMENT_OPEN_FAILURE =  12 ; 
      MAPI_E_ATTACHMENT_WRITE_FAILURE =  13 ; 
      MAPI_E_UNKNOWN_RECIPIENT =  14 ; 
      MAPI_E_BAD_RECIPTYPE =  15 ; 
      MAPI_E_NO_MESSAGES =  16 ; 
      MAPI_E_INVALID_MESSAGE =  17 ; 
      MAPI_E_TEXT_TOO_LARGE =  18 ; 
      MAPI_E_INVALID_SESSION =  19 ; 
      MAPI_E_TYPE_NOT_SUPPORTED =  20 ; 
      MAPI_E_AMBIGUOUS_RECIPIENT =  21 ; 
      MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT; 
      MAPI_E_MESSAGE_IN_USE =  22 ; 
      MAPI_E_NETWORK_FAILURE =  23 ; 
      MAPI_E_INVALID_EDITFIELDS =  24 ; 
      MAPI_E_INVALID_RECIPS =  25 ; 
      MAPI_E_NOT_SUPPORTED =  26 ; 
    } 

    case MError of 
      MAPI_E_USER_ABORT: 
        begin 
          if Assigned(FOnUserAbort) then 
            FOnUserAbort(Self); 
        end; 
      SUCCESS_SUCCESS: 
        begin 
          if Assigned(FOnSuccess) then
            FOnSuccess(Self); 
        end 
      else 
        begin 
          if Assigned(FOnMapiError) then 
            FOnMapiError(Self, MError); 
        end; 

    end; 
  finally 
    { Finally we do the cleanups, the message should be on its way } 
    { +> Changes by Andreas Hoerig [mailto:andreas.hoerig@sillner.com] } 
    PRecip := Recipients; 
    for i :=  1  to MapiMessage.nRecipCount do 
      begin 
        StrDispose(PRecip^.lpszAddress); 
        Inc(PRecip) 
      end; 
    { +< Changes } 
    FreeMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc)); 
    { +> Changes due to Ken Halliwell [mailto:kjhalliwell@aol.com] } 
    if Assigned(PFiles) then 
      FreeMem(PFiles, MapiMessage.nFileCount * sizeof(TMapiFileDesc)); 
    { +< Changes } 
  end; 
end; 

{ 
  Please treat this as free. If you improve the component 
  I would be glad to get a copy. 
} 

end. 
...
Рейтинг: 0 / 0
отправка почты
    #32188798
Oleg Romantsev
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
А можно ли через ShelExecute (mailto) прикрепить аттачмент?
...
Рейтинг: 0 / 0
12 сообщений из 12, страница 1 из 1
Форумы / Delphi [игнор отключен] [закрыт для гостей] / отправка почты
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]