A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 18th 07, 01: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
  #2  
Old July 19th 07, 09: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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Someone sending mail from my outlook Vic Spainhower Outlook - General Queries 11 May 15th 07 10:33 PM
Outlook Freezes when sending mail william Outlook - General Queries 0 December 21st 06 03:21 PM
Sending from Word with Outlook COM Addin james Add-ins for Outlook 0 May 30th 06 03:44 PM
Sending mail with attachment from my vb6 addin [email protected] Add-ins for Outlook 1 April 27th 06 09:03 AM
Addin HELP - Preview Pane, where is the mail event? Joey Outlook - Using Forms 0 March 17th 06 01:29 AM


All times are GMT +1. The time now is 09:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.