An Outlook add-in should never contain a statement like this:
myOlApp = New Outlook.Application
Instead, you need to be using the Outlook.Application object exposed by the application architecture. Are you using VSTO 2005 SE or IDTExtensibility2?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
"Dewey" wrote in message ...
Please help!
I've been trying to send an email from within a COM addin in VB.net 2005,
but keep getting a very weird message:
'Unable to cast object of type 'System.__ComObject' to type
'Microsoft.Office.Interop.Outlook.ApplicationClass '.
I am trying to send from a form in a COM addin that I open from within
Outlook
Here's the sub I use:
-----------------------------
Private Sub SendMail( )
Dim myOlApp As Outlook._Application
'Dim myOlApp As Object
Dim MyItem As Outlook._MailItem
Dim luvRecipients As Outlook.Recipients
Dim luvRecipient As Outlook.Recipient
myOlApp = New Outlook.Application
'MyItem = myOlApp.CreateItem(OlItemType.olMailItem)
'MyItem.Display()
On Error Resume Next
'this is the body of the email
MyItem.Subject = "Image sending test"
MyItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
MyItem.HTMLBody = "HTMLDIV ALIGN=CENTERIMG
src='\\Fil-nw04-10\hello.jpg/HTML"
MyItem.Send()
End Sub
-----------------------------
Thanks very much for any help in advance!
-Josh