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" <Dewey.RemoveThis@discussions.microsoft.com> wrote in message news:701C8174-91B2-4309-9A29-647A0F335A73@microsoft.com...
> 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 = "<HTML><DIV ALIGN=CENTER><IMG
> src='\\Fil-nw04-10\hello.jpg></HTML>"
>
> MyItem.Send()
>
> End Sub
> -----------------------------
>
> Thanks very much for any help in advance!
>
> -Josh
>