Ik zit met een probleem. Ik heb onderstaand programma gedownload en geimplenteerd in mijn eigen programma. Het gaat om een op MAPI gebaseerd e-mail programma. Het werkt verder goed alleen als ik een attachment van meer dan 8 karakters wil toevoegen dan kort hij dit bij het versturen weer af naar 8 karakters.
Ben niet zo goed in Delphi en heb code aardig doorgezocht maar kan het niet vinden. Misschien zie ik het over het hoofd maar 2 of meer mensen zien meer dan 1 zeg ik maar.......
sorry voor de lap tekst, maar dat ik zou niet anders weten hoe ik het moet formuleren. Zodra ik weet in welk stuk code het zit haal ik de rest wel weg.
Ben niet zo goed in Delphi en heb code aardig doorgezocht maar kan het niet vinden. Misschien zie ik het over het hoofd maar 2 of meer mensen zien meer dan 1 zeg ik maar.......
sorry voor de lap tekst, maar dat ik zou niet anders weten hoe ik het moet formuleren. Zodra ik weet in welk stuk code het zit haal ik de rest wel weg.
code:
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
| procedure TMainForm.FormCreate(Sender: TObject);
begin
(* Icon := Application.Icon; *)
Application.Title := 'TEmail demonstration';
Messages := TStringlist.Create;
Messages.Sorted := false;
nUnread := -1;
MsgIndex := 0;
Abort := False;
{$IFDEF TESTCOMPON}
Email1 := TEmail.Create(Self);
{$ENDIF TESTCOMPON}
if Email1.Logon <> EMAIL_OK then
MessageDlg('MAPI Logon failed', mtError, [mbOk], 0);
Caption := Caption + ' [demo of TEmail ' + Email1.Version + ']';
end;
{ Cleanup. }
procedure TMainForm.FormDestroy(Sender: TObject);
begin
Messages.Free;
Messages := nil;
if Email1.Logoff <> EMAIL_OK then
MessageDlg('MAPI Logoff failed', mtError, [mbOk], 0);
end;
{ Send mail. }
procedure TMainForm.SendClick(Sender: TObject);
var
PlongText: PChar;
TextSize: integer;
begin
if lbTo.Items.Count > 0 then
Email1.Recipient.Assign(lbTo.Items);
if lbCC.Items.Count > 0 then
Email1.CC.Assign(lbCC.Items);
if lbBCC.Items.Count > 0 then
Email1.BCC.Assign(lbBCC.Items);
if lbAttach.Items.Count > 0 then
Email1.Attachment.Assign(lbAttach.Items);
TextSize := MessageText.GetTextLen + 1;
PlongText := StrAlloc(TextSize);
try
MessageText.GetTextBuf(PlongText, TextSize);
Email1.SetLongText(PlongText);
finally
StrDispose(PlongText);
end;
Email1.Subject := MessageSubject.Text;
if Email1.SendMail <> EMAIL_OK then
begin
MessageDlg('MAPI Sendmail failed', mtError, [mbAbort], 0);
Close;
end
else
begin
Recipient.Clear;
CC.Clear;
BCC.Clear;
Attach.Clear;
AcknowledgeCheck.State := cbUnchecked;
MessageSubject.Clear;
MessageText.Clear;
lbTo.Clear;
lbCC.Clear;
lbAttach.Clear;
lbBCC.Clear;
{ Clear internal state of TEmail for safety }
Email1.Clear;
end;
end;
{ Add recipient to listbox on exit. }
procedure TMainForm.RecipientExit(Sender: TObject);
var
Recip: SString;
begin
with Sender as TEdit do
begin
if Length(Text) > 0 then
begin
Recip := Email1.CheckRecipient(Text);
Text := '';
if Length(Recip) > 0 then
begin
if Sender = Recipient then
lbTo.Items.Add(Recip)
else
if Sender = CC then
lbCC.Items.Add(Recip)
else
if Sender = BCC then
lbBCC.Items.Add(Recip);
end;
SetFocus;
end;
end;
end;
{ Remove recipient from lbTo button. }
procedure TMainForm.btnRemoveClick(Sender: TObject);
var
AListbox: TListbox;
begin
AListbox := nil;
if Sender = btnToRemove then
AListbox := lbTo
else
if Sender = btnCCRemove then
AListbox := lbCC
else
if Sender = btnBCCRemove then
AListbox := lbBCC
else
if Sender = btnAttachRemove then
AListbox := lbAttach;
if AListbox <> nil then
with AListbox do
begin
if (ItemIndex <> -1) then
begin
Items.Delete(ItemIndex);
end
else
begin
{$IFDEF WIN32}
MessageBeep($FFFFFFFF);
{$ELSE}
MessageBeep($FFFF);
{$ENDIF WIN32}
ItemIndex := 0;
SetFocus;
end;
end;
end;
{ Add button has been clicked }
procedure TMainForm.btnAddClick(Sender: TObject);
var
AnEdit: TEdit;
begin
AnEdit := nil;
if Sender = btnToAdd then
AnEdit := Recipient
else
if Sender = btnCCAdd then
AnEdit := CC
else
if Sender = btnBCCAdd then
AnEdit := BCC;
if AnEdit <> nil then
begin
RecipientExit(AnEdit);
AnEdit.SetFocus;
end;
end;
{ Move attachment to lbAttach on exit. }
procedure TMainForm.AttachExit(Sender: TObject);
var
Attachment : SString;
begin
with Attach do
begin
if Length(Text) > 0 then
begin
Attachment := Email1.CheckAttachment(ExpandFilename(Text));
if Length(Attachment) > 0 then
lbAttach.Items.Add(Attachment)
else
begin
with OpenAttachm do
begin
Filename := Text;
if Execute then
lbAttach.Items.Add(Filename);
end;
end;
Text := '';
SetFocus;
end;
end;
end;
{ Receipt requested checkbox. }
procedure TMainForm.AcknowledgeCheckClick(Sender: TObject);
begin
Email1.Acknowledge := AcknowledgeCheck.Checked;
end;
{ Read next email message button. }
procedure TMainForm.ReadMailClick(Sender: TObject);
begin
{ count number of unread messages }
if nUnread = -1 then
begin
Panel1.Caption := 'Counting unread messages, please wait...';
Screen.Cursor := crHourGlass;
try
Update;
nUnread := Email1.CountUnread;
finally
Screen.Cursor := crDefault;
end;
Panel1.Caption := '';
end;
{ retrieve all message Id's }
if Messages.Count = 0 then
begin
Email1.MessageId := '';
Screen.Cursor := crHourGlass;
try
Application.ProcessMessages;
Email1.GetNextMessageId;
while (not Abort) and (Length(Email1.MessageId) <> 0) do
begin
Application.ProcessMessages; { needed for ESC bail-out key to work }
Messages.Add(Email1.MessageId);
Panel1.Caption := Format('Retrieving all messages, please wait... (%d)',
[Messages.Count]);
Update;
Email1.GetNextMessageID;
end;
MsgIndex := 0;
finally
Screen.Cursor := crDefault;
end;
Panel1.Caption := '';
if Abort then
exit;
MessageDlg( Format( 'There are %d messages of which %d are unread.',
[Messages.Count, nUnread]),
mtInformation, [mbOK], 0);
end;
with Email1 do
begin
if MsgIndex < Messages.Count then { if still messages left : }
begin
MessageId := Messages.Strings[MsgIndex];
{ this is the message to fetch }
Inc(MsgIndex);
end
else
begin
MsgIndex := 0; { else clear all message stuff }
Messages.Clear; { so that we can read them again}
nUnread := -1; { and inform the user }
MessageDlg('No more messages.', mtInformation, [mbOk], 0);
end;
HeaderOnly := False; { retrieve entire message }
LeaveUnread := True; { do not mark the messages read }
NoAttachments := not ReturnAttachm.Checked;
{ if False : you have to delete the temp files !! }
ReadMail; { fetch the message }
lbTo.Clear; { store recipients in lbTo }
lbTo.Items.Assign(Recipient);
lbCC.Clear; { store CCs in lbCC }
lbCC.Items.Assign(CC);
lbBCC.Clear; { and BCCs in lbBCC }
lbBCC.Items.Assign(BCC);
lbAttach.Clear; { store attachments in lbAttach if NoAttachments False }
lbAttach.Items.Assign(Attachment);
if (NoAttachments = False) and (lbAttach.Items.Count > 0) then
lbAttach.ShowHint := True
else
lbAttach.ShowHint := False;
MessageText.Clear;
if Email1.Text = '' then { set subject and text fields }
MessageText.SetTextBuf(GetLongText)
else
MessageText.Text := Email1.Text;
MessageSubject.Text := Email1.Subject;
{ show originator in the panel }
Panel1.Caption := Format('From: %s (%s)', [Originator, DateRecvd]);
if Unread then
with Panel1 do
Caption := Caption + ' *unread*';
end;
end;
{ Escape closes the form. }
procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
var
OldCursor: TCursor;
begin
if Key = #$1B then
begin
OldCursor := Screen.Cursor;
Screen.Cursor := crDefault;
try
if MessageDlg( 'Are you sure that you want to close and leave this form?',
mtConfirmation,
[mbYes, mbNo], 0) = mrYes then
begin
Abort := True;
Close;
end;
finally
Screen.Cursor := OldCursor;
end;
end;
end;
{ Present an address dialog box. }
procedure TMainForm.SomeAddressButtonClick(Sender: TObject);
begin
Email1.Recipient.Assign(lbTo.Items);
Email1.CC.Assign(lbCC.Items);
Email1.BCC.Assign(lbBCC.Items);
Email1.Address;
lbTo.Clear; { store recipients in lbTo }
lbTo.Items.Assign(Email1.Recipient);
lbCC.Clear; { store CCs in lbCC }
lbCC.Items.Assign(Email1.CC);
lbBCC.Clear; { and BCCs in lbBCC }
lbBCC.Items.Assign(Email1.BCC);
end;
{ Open attachment dialog. }
procedure TMainForm.AttachButtonClick(Sender: TObject);
begin
with OpenAttachm do
if Execute then
lbAttach.Items.Add(Filename);
end;
procedure TMainForm.lbDeleteDown(Sender: TObject; var Key: Word; Shift:
TShiftState);
var
iIndex: integer;
begin
if (Key = VK_DELETE) and (Sender is TListbox) then
with TListbox(Sender) do
begin
iIndex := ItemIndex;
if iIndex <> -1 then
begin
Items.Delete(iIndex);
if Items.Count > 0 then
ItemIndex := iIndex;
end
else
begin
{$IFDEF WIN32}
MessageBeep($FFFFFFFF);
{$ELSE}
MessageBeep($FFFF);
{$ENDIF WIN32}
ItemIndex := 0;
SetFocus;
end;
end;
end;
procedure TMainForm.ReturnAttachmClick(Sender: TObject);
begin
{ if False : you have to delete the temp files !! }
Email1.NoAttachments := not ReturnAttachm.Checked;
end;
procedure TMainForm.lbAttachDblClick(Sender: TObject);
var
Index : integer;
begin
Index := lbAttach.ItemIndex;
if Index < 0 then
exit;
SaveDialog1.Filename := ExtractFileName(lbAttach.Items[Index]);
if SaveDialog1.Execute then
begin
Email1.CopyAttachment(index, SaveDialog1.Filename, True);
end;
end;
procedure TMainForm.bNewMailClick(Sender: TObject);
var
OldCursor: TCursor;
begin
OldCursor := Screen.Cursor;
Screen.Cursor := crHourGlass;
try
Panel1.Caption := 'Downloading new messages - please wait...';
Update;
Email1.DownLoad;
finally
Panel1.Caption := '';
Screen.Cursor := OldCursor;
end;
end;
end. |