View Single Post
  #1  
Old July 18th 07, 12:28 AM posted to microsoft.public.outlook.program_addins
Dewey
external usenet poster
 
Posts: 26
Default Please help! Sending mail in Outlook from a COM addin.

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 = " '--(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
Ads