Please help! Sending mail in Outlook from a COM addin.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Please help! I am trying to send an email from within an Outlook COM addin,
and I am getting a strange error:

Unable to cast object of type 'System.__ComObject' to type
'Microsoft.Office.Interop.Outlook.ApplicationClass'.

Here's the code I'm using:

'-------------------------------
Private Sub SendMail( )


Dim myOlApp As Outlook._Application
Dim MyItem As Outlook._MailItem
myOlApp = New Outlook.Application
MyItem = myOlApp.CreateItem(OlItemType.olMailItem)
MyItem.Display( )
On Error Resume Next

MyItem.To = "(e-mail address removed)" '<--(Changed)


'this is the body of the email
MyItem.Subject = "test 1 2 3"
MyItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML


MyItem.Send()

End Sub
'-------------------------------

Any help is greatly appreciated. Thank you!
-Josh
 
Hi Dewey,

I think you can solve your problem when you write your assignments like this:

Set myOlApp = New Outlook.Application
Set MyItem = myOlApp.CreateItem(OlItemType.olMailItem)

Hope this helps
Christian
 
Back
Top