Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Delphi 7 - TOutlookApplication - Test Program Error


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Sep 12, 2017 12:50 AM Last Post By: Robert Triest
Mark Moss

Posts: 1
Registered: 7/20/06
Delphi 7 - TOutlookApplication - Test Program Error  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 7, 2017 3:57 PM
If someone could please give me some guidance with this test program using the TOutlookApplication Component to try and access Outlook Mail Items in a Folder.

While it compiles and seems to work it gives the following error when I added the " ListBox2.Items.Add( itms.Body ); "


Debugger Exception Notification

Project Project1.exe raised exception class EOleException with message 'Unspecified error'. Process stopped. Use Step or Run to continue.

OK Help

If you comment out that Line, the ListBox1 will fill up with itms.Subject for all of the messages in your inbox.

Any help would be greatly appreciated.

Mark Moss

{==============================================================================}

Unit1.dfm

object Form1: TForm1
Left = 279
Top = 139
Width = 1305
Height = 675
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 40
Top = 104
Width = 409
Height = 457
ItemHeight = 13
TabOrder = 0
end
object ListBox2: TListBox
Left = 672
Top = 104
Width = 609
Height = 505
ItemHeight = 13
TabOrder = 1
end
object OutlookApplication1: TOutlookApplication
AutoConnect = False
ConnectKind = ckRunningOrNew
AutoQuit = False
Left = 392
Top = 24
end
end

{======================================================================}

Unit1.pas

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleServer, OutlookXP, Outlook2000, StdCtrls;

type
TForm1 = class(TForm)
OutlookApplication1: TOutlookApplication;
ListBox1: TListBox;
ListBox2: TListBox;

procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{==============================================================================}

procedure TForm1.FormShow(Sender: TObject);
var

i: Integer;
NmSpace: NameSpace;
Folder: MAPIFolder;
itm: Variant;
criteria: String;
itms: MailItem;
objMsg: ContactItem;

w: WideString;
s: String;

begin

OutlookApplication1.Connect;
NmSpace := OutlookApplication1.GetNamespace('MAPI');
NmSpace.Logon('', '', False, False);
Folder := NmSpace.GetDefaultFolder(olFolderInbox);

For i:= 1 to Folder.Items.Count do
begin
itms := Folder.Items.Item(i) As MailItem;

ListBox1.Items.Add( itms.Subject );

//now you have access to all these

{itms.SenderName}
{itms.CC}
{itms.BCC}
{itms.Subject}
{itms.Body}

ListBox2.Items.Add( itms.Body );

end;

end;

{==============================================================================}

end.

{==============================================================================}

Project1.dpr

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

{==============================================================================}

Robert Triest

Posts: 687
Registered: 3/24/05
Re: Delphi 7 - TOutlookApplication - Test Program Error  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 11, 2017 1:49 AM   in response to: Mark Moss in response to: Mark Moss
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleServer, OutlookXP, Outlook2000, StdCtrls;

See if you can use only one library instead of 2 (OutlookXP, Outlook2000) Prefer Outlook2000 (has MailItem)
Did you try HTMLBody instead of Body?
See if you have problems with Outlook security. (Maybe you are not allowed to do certain things..)

Note:
I tested the example and also with adding the Body line works OK here..

Edited by: Robert Triest on Sep 11, 2017 10:57 AM
Mark Moss

Posts: 4
Registered: 9/15/14
Re: Delphi 7 - TOutlookApplication - Test Program Error  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 11, 2017 10:08 AM   in response to: Robert Triest in response to: Robert Triest
Robert Triest wrote:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleServer, OutlookXP, Outlook2000, StdCtrls;

See if you can use only one library instead of 2 (OutlookXP, Outlook2000) Prefer Outlook2000 (has MailItem)
Did you try HTMLBody instead of Body?
See if you have problems with Outlook security. (Maybe you are not allowed to do certain things..)

Note:
I tested the example and also with adding the Body line works OK here..

Edited by: Robert Triest on Sep 11, 2017 10:57 AM

Robert, thank you so very much for your reply,

I have removed the OutlookXP, compiled and Same Results, I have also done the reverse removed Outlook2000 compiled and Same Results.

I am Using Outlook 2007 SP3 MSO (12.0.6741.5000)

Any Ideas?

Mark Moss
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Delphi 7 - TOutlookApplication - Test Program Error  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 12, 2017 12:50 AM   in response to: Mark Moss in response to: Mark Moss
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02