Help!

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


Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Program Add-Ins RSS
Next:  Please help! Sending mail from a COM add-in  
Author Message
Dewey
External


Since: May 26, 2006
Posts: 16



PostPosted: Tue Jul 17, 2007 4:28 pm    Post subject: Please help! Sending mail in Outlook from a COM addin.
Archived from groups: microsoft>public>outlook>program_addins (more info?)

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 = "me@hotmail.com" '<--(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
Back to top
Christian Havel
External


Since: Jul 03, 2007
Posts: 28



PostPosted: Thu Jul 19, 2007 12:44 am    Post subject: RE: Please help! Sending mail in Outlook from a COM addin. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 = "me@hotmail.com" '<--(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
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Program Add-Ins All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum