Tried that but when I try to send a second mail I get the error;
Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.Runtime.InteropServices.InvalidComObjectExc eption: COM object that
has been separated from its underlying RCW can not be used.
Here is the jist of my code;
Private WithEvents OutlookApp As Outlook.Application
Private WithEvents em As Outlook.MailItem
OutlookApp = New Outlook.Application '<=== I am getting the above error
here.
em = OutlookApp.CreateItemFromTemplate(EmailTemplate)
em.To = "me@mydomain.com"
em.Display(True)
' em = Nothing
' OutlookApp = Nothing ' This caused straneg effects
' OutlookApp.Quit() ' This caused outlook app to close too
System.Runtime.InteropServices.Marshal.ReleaseComO bject(OutlookApp) ' This
is what I am trying now
"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:98****************************@phx.gbl...
Hi John
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject
(outlookapp)
Kind Regards
Jorge
-----Original Message-----
Hi
I am using outlook to display and send new mail message
from within vb.net.What is the correct way to close outlook after I am
done? If I useoutlookapp.quit then any running outlook copy also
closes which isinconvenient for user. If I use outlookapp = nothing
then strange thingshappen afterwards, such as the mail message not being
sent when pressingSend button. Is there a way to close only the instance
of outlook that wasopened from within vb.net and not the main outlook app
which was runseparately?
Thanks
Regards
.