Board index » delphi » Error Using Outlook - Outlook Performed Illegal Operation

Error Using Outlook - Outlook Performed Illegal Operation

Hello,

I am writing a simple application and wish to be able to send an e-mail message
whenever a certain conditions exists (very simple).

I am using Outlook 2000 as the Mail Agent / Server and Delphi 5, Professional Edition.
I have the following code:

-------------

procedure TForm1.Button1Click(Sender: TObject);

const
  olMailItem = 0;

var
  Outlook: OutLookApplication;
  NewMail: Variant;

begin
  Outlook := CoOutlookApplication.Create;
  NewMail := Outlook.CreateItem(olMailItem);

  NewMail.Recipients.Add ('hwco...@hotmail.com');
  NewMail.Subject := 'Delphi Test E-mail';
  NewMail.Body := 'This is a test email from Delphi App.';

  // Resolve Names and Send E-mail
  NewMail.Recipients.ResolveAll;
  NewMail.Send;

end

When I run this code with Outlook open is works fine and sends the test e-mail.
However if I have Outlook closed (which would normally be the case) it does
not work and I get the following Error:

"Outlook has performed an Illegal operation and will be closed"

Am I doing something wrong or is it a problem with Outlook???  I have tried using
both early and late binding but I get the same problem.

Anyone know why??

Another quick question is why in Early Binding do you need to define the olMailItem
constant (why is it not in the type library??) but you do not if using Late
Binding??

Thanks,

Hugh

 

Re:Error Using Outlook - Outlook Performed Illegal Operation


I can see the header of your post on my ISP's copy of this
newsgroup, but it hasn't been sent to Borland's news
server.
That means that most of the people who read Borland's
newsgroups cannot see your post.

To post messages that other people will see, you need to
connect to Borland's server, newsgroups.borland.com,
directly. Here's a link with instructions if you don't know
how:
http://www.borland.com/newsgroups/newsinfo.html

If you cannot connect directly to newsgroups because
of a firewall, you can post to Borland's newsgroups
via the web pages at http://newsgroups.borland.com/

--
Deborah Pate

Re:Error Using Outlook - Outlook Performed Illegal Operation


Hello,

I am writing a simple application and wish to be able to send an e-mail message
whenever a certain conditions exists (very simple).

I am using Outlook 2000 as the Mail Agent / Server and Delphi 5, Professional Edition.
I have the following code:

-------------

procedure TForm1.Button1Click(Sender: TObject);

const
  olMailItem = 0;

var
  Outlook: OutLookApplication;
  NewMail: Variant;

begin
  Outlook := CoOutlookApplication.Create;
  NewMail := Outlook.CreateItem(olMailItem);

  NewMail.Recipients.Add ('hwco...@hotmail.com');
  NewMail.Subject := 'Delphi Test E-mail';
  NewMail.Body := 'This is a test email from Delphi App.';

  // Resolve Names and Send E-mail
  NewMail.Recipients.ResolveAll;
  NewMail.Send;

end

When I run this code with Outlook open is works fine and sends the test e-mail.
However if I have Outlook closed (which would normally be the case) it does
not work and I get the following Error:

"Outlook has performed an Illegal operation and will be closed"

Am I doing something wrong or is it a problem with Outlook???  I have tried using
both early and late binding but I get the same problem.

Anyone know why??

Another quick question is why in Early Binding do you need to define the olMailItem
constant (why is it not in the type library??) but you do not if using Late
Binding??

Thanks,

Hugh

Re:Error Using Outlook - Outlook Performed Illegal Operation


Hello,

I am writing a simple application and wish to be able to send an e-mail message
whenever a certain conditions exists (very simple).

I am using Outlook 2000 as the Mail Agent / Server and Delphi 5, Professional Edition.
I have the following code:

-------------

procedure TForm1.Button1Click(Sender: TObject);

const
  olMailItem = 0;

var
  Outlook: OutLookApplication;
  NewMail: Variant;

begin
  Outlook := CoOutlookApplication.Create;
  NewMail := Outlook.CreateItem(olMailItem);

  NewMail.Recipients.Add ('hwco...@hotmail.com');
  NewMail.Subject := 'Delphi Test E-mail';
  NewMail.Body := 'This is a test email from Delphi App.';

  // Resolve Names and Send E-mail
  NewMail.Recipients.ResolveAll;
  NewMail.Send;

end

When I run this code with Outlook open is works fine and sends the test e-mail.
However if I have Outlook closed (which would normally be the case) it does
not work and I get the following Error:

"Outlook has performed an Illegal operation and will be closed"

Am I doing something wrong or is it a problem with Outlook???  I have tried using
both early and late binding but I get the same problem.

Anyone know why??

Another quick question is why in Early Binding do you need to define the olMailItem
constant (why is it not in the type library??) but you do not if using Late
Binding??

Thanks,

Hugh

Re:Error Using Outlook - Outlook Performed Illegal Operation


<<Hugh Cowan:
However if I have Outlook closed (which would normally be
the case) it does not work and I get the following Error:

Quote

FWIW, I can run your code without any problem. Can you find
out which line causes the error?

<<Hugh:
Another quick question is why in Early Binding do you need
to define the olMailItem constant (why is it not in the
type library??)

Quote

You don't have to. It's declared in Outlook2000.pas, or
Outlok 8.pas if you're using the Office97 components (which
are in your Delphi\Ocx\Servers directory). If you use the
TOutlookApplication component the relevant file will be
added to your uses clause.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error Using Outlook - Outlook Performed Illegal Operation


Hi Deborah,

Thanks for you reply and for your other message (re: using Borland Newsgroups Direct) -- I don't know if you got it but
I did send you an e-mail thanking you.

The error occurs in the first line when it tries to create an instance of the Outlook Application:
(Outlook := CoOutlookApplication.Create)

Apparantely this is a know problem??  I originally tried this in VB / VBA as I actually want to use the code in an Excel
spreadsheet that will send an e-mail when there is a specific error on the spreadsheet.

I wrote the code in VBA and I got the same error / problem (again when first trying to create an instance of the Outlook
Application Object).  At the time I didn't know whether it was my machine or what.  I asked several Outlook / VBA
people and got back responses saying that it was a known problem with VBA and Outlook.

I then decided that I would try using Delphi instead and create an ActiveX object that Excel could call that would
indirectly send the e-mail instead (through the ActiveX control).

However, as I noted before, I seem to get the same exact problem when trying with Delphi.

I am running Windows 98 with Outlook 2000 (Office 2000).  And the problem is consistent.  Whenever I try running the
Application with Outlook closed I get the error -- but as soon as I run / open Outlook first it works fine.

I am really surprised (with all the previous information) that you were able to get it to work without any problems.

I do have one other side question that you might be able to answer.  When using COM/OLE to access objects such
as Outlook -- does the OS actually run the program or does it just access the COM objects behind the scences??

The reason that I am asking is the machines that will be running this Excel Spreadsheet have Windows Policies installed
and have been setup with Restrictions in place (meaning they cannot run any programs other than Excel).

I don't know whether the restrictions will prevent the accessing of the Outlook object or not!! (I was going to do a test and
find out -- however I can't get the test to work under normal circumstances let alone with restrictions in place).

Thanks,

Hugh

"Deborah Pate (TeamB)" <d.p...@cableinet.co.not-this-bit.uk> wrote:

Quote
><<Hugh Cowan:>However if I have Outlook closed (which would normally be
>the case) it does not work and I get the following Error:

>FWIW, I can run your code without any problem. Can you find
>out which line causes the error?

><<Hugh:
>Another quick question is why in Early Binding do you need
>to define the olMailItem constant (why is it not in the
>type library??)

>You don't have to. It's declared in Outlook2000.pas, or
>Outlok 8.pas if you're using the Office97 components (which
>are in your Delphi\Ocx\Servers directory). If you use the
>TOutlookApplication component the relevant file will be
>added to your uses clause.

>--
>Deborah Pate (TeamB) http://delphi-jedi.org

>  Use Borland servers; TeamB don't see posts via ISPs
>  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error Using Outlook - Outlook Performed Illegal Operation


<<Hugh Cowan:
I am really surprised (with all the previous information)
that you were able to get it to work without any problems.

Quote

Just tried it again - works perfectly. Is this a local
instance of Outlook, though? Under Windows 9x you can't
connect to a remote server that isn't already running, it's
a DCOM limitation.

I don't know much about policies and security issues, I'm
afraid. I did get your email, thanks - I meant to put a
note at the end of my other message, but got sidetracked,
sorry.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error Using Outlook - Outlook Performed Illegal Operation


I just tried my setup again (just to make sure) and again I get the "illegal operation error".  This is the information from
the debug screen:

OUTLOOK caused an invalid page fault in
module MSO9.DLL at 0167:30a6f987.
Registers:
EAX=00000000 CS=0167 EIP=30a6f987 EFLGS=00010246
EBX=00000ac4 SS=016f ESP=0056f828 EBP=0056f878
ECX=308f0990 DS=016f ESI=00000000 FS=48b7
EDX=00ef002c ES=016f EDI=00790748 GS=0000
Bytes at CS:EIP:
8b 0c 30 e8 0c 00 00 00 83 c6 04 4b 75 e8 5e 5b
Stack dump:
00000000 00790940 00000001 00000000 30a6f74d 00790748 00000000 00000000 00790940 00000003 00000001 00000001 00000001 00690794 00790a8c 00000001

As far as I know it is a local instance (I didn't know you could have a remote instance).

If have the program (Outlook) on your hard drive and running it from there constitutes a local instance than that is
what I have.

I have tried just about everything that I know but I cannot get it to work.  I know that they have an odd back-end
for the mail server itself (I think they are running it off Unix or something) but to me that shouldn't have anything to
do with starting the Outlook application.

Oh well, if you can think of anything else please let me know.  Just for reference, are you running Windows 98
or something else?

Thanks,

Hugh

"Deborah Pate (TeamB)" <d.p...@cableinet.co.not-this-bit.uk> wrote:

Quote
><<Hugh Cowan:>I am really surprised (with all the previous information)
>that you were able to get it to work without any problems.

>Just tried it again - works perfectly. Is this a local
>instance of Outlook, though? Under Windows 9x you can't
>connect to a remote server that isn't already running, it's
>a DCOM limitation.

>I don't know much about policies and security issues, I'm
>afraid. I did get your email, thanks - I meant to put a
>note at the end of my other message, but got sidetracked,
>sorry.

>--
>Deborah Pate (TeamB) http://delphi-jedi.org

>  Use Borland servers; TeamB don't see posts via ISPs
>  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error Using Outlook - Outlook Performed Illegal Operation


<<Hugh Cowan:
Just for reference, are you running Windows 98 or something
else?

Quote

Windows 98SE, Outlook 2000, installed in Internet Mode
only. But your MSO9.dll seems likely to be the problem:
http://support.microsoft.com/support/kb/articles/Q241/8/17.
ASP

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Re:Error Using Outlook - Outlook Performed Illegal Operation


Wow,

Thanks Deborah for the new information.  I found that Article Q241817 did not actually solved my problem, but it
did point to Article Q240813 which states that if you are running Outlook with the Personal Folder Backup agent enabled
and you are not running Outlook at the time then you will get this error message (and this is my case).

I don't know why it is considered an error when I haven't done anything wrong or invalid!! I don't know why
Microsoft couldn't just fixed the problem.

Thanks again for your help me and pointing me in the right direction.

Hugh,

"Deborah Pate (TeamB)" <d.p...@cableinet.co.not-this-bit.uk> wrote:

Quote
><<Hugh Cowan:>Just for reference, are you running Windows 98 or something
>else?

>Windows 98SE, Outlook 2000, installed in Internet Mode
>only. But your MSO9.dll seems likely to be the problem:
>http://support.microsoft.com/support/kb/articles/Q241/8/17.
>ASP

>--
>Deborah Pate (TeamB) http://delphi-jedi.org

>  Use Borland servers; TeamB don't see posts via ISPs
>  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads