View Single Post
  #2  
Old July 19th 07, 08:44 AM posted to microsoft.public.outlook.program_addins
Christian Havel
external usenet poster
 
Posts: 43
Default Please help! Sending mail in Outlook from a COM addin.

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

"Dewey" wrote:

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