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 from a COM add-in



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 18th 07, 01:16 AM posted to microsoft.public.outlook.program_addins
Dewey
external usenet poster
 
Posts: 26
Default Please help! Sending mail from a COM add-in

Please help!

I've been trying to send an email from within a COM addin in VB.net 2005,
but keep getting a very weird message:

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

I am trying to send from a form in a COM addin that I open from within
Outlook


Here's the sub I use:
-----------------------------
Private Sub SendMail( )

Dim myOlApp As Outlook._Application
'Dim myOlApp As Object
Dim MyItem As Outlook._MailItem
Dim luvRecipients As Outlook.Recipients
Dim luvRecipient As Outlook.Recipient
myOlApp = New Outlook.Application
'MyItem = myOlApp.CreateItem(OlItemType.olMailItem)
'MyItem.Display()
On Error Resume Next


'this is the body of the email
MyItem.Subject = "Image sending test"
MyItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
MyItem.HTMLBody = "HTMLDIV ALIGN=CENTERIMG
src='\\Fil-nw04-10\hello.jpg/HTML"

MyItem.Send()

End Sub
-----------------------------

Thanks very much for any help in advance!

-Josh

  #2  
Old July 18th 07, 01:24 AM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Please help! Sending mail from a COM add-in

An Outlook add-in should never contain a statement like this:

myOlApp = New Outlook.Application

Instead, you need to be using the Outlook.Application object exposed by the application architecture. Are you using VSTO 2005 SE or IDTExtensibility2?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Dewey" wrote in message ...
Please help!

I've been trying to send an email from within a COM addin in VB.net 2005,
but keep getting a very weird message:

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

I am trying to send from a form in a COM addin that I open from within
Outlook


Here's the sub I use:
-----------------------------
Private Sub SendMail( )

Dim myOlApp As Outlook._Application
'Dim myOlApp As Object
Dim MyItem As Outlook._MailItem
Dim luvRecipients As Outlook.Recipients
Dim luvRecipient As Outlook.Recipient
myOlApp = New Outlook.Application
'MyItem = myOlApp.CreateItem(OlItemType.olMailItem)
'MyItem.Display()
On Error Resume Next


'this is the body of the email
MyItem.Subject = "Image sending test"
MyItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
MyItem.HTMLBody = "HTMLDIV ALIGN=CENTERIMG
src='\\Fil-nw04-10\hello.jpg/HTML"

MyItem.Send()

End Sub
-----------------------------

Thanks very much for any help in advance!

-Josh

  #3  
Old July 18th 07, 01:48 AM posted to microsoft.public.outlook.program_addins
Dewey
external usenet poster
 
Posts: 26
Default Please help! Sending mail from a COM add-in

Hi Sue

I'm using IDTExtensibility2. However, and excuse my beginner-ness, but I
did think to try passing that object, but it's created in the "OnConnection"
sub in another class. How can I pass it properly to the class with my form
that sends the email...or should I even be taking that route? (Sorry if this
makes no sense...I'm still a very VB6-oriented individual). My old fashoined
and sloppy sense would have me use a global variable, but I'm guessing that's
out here in .net land. Here's where the application object is first exposed
in IDTExtensibility2:



Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection

If (connectMode Extensibility.ext_ConnectMode.ext_cm_Startup)
Then _
Call OnStartupComplete(custom)

olApp = CType(application,
Microsoft.Office.Interop.Outlook.Application)

End Sub ( )



Thank you very much for your help
-Josh



"Sue Mosher [MVP-Outlook]" wrote:

An Outlook add-in should never contain a statement like this:

myOlApp = New Outlook.Application

Instead, you need to be using the Outlook.Application object exposed by the application architecture. Are you using VSTO 2005 SE or IDTExtensibility2?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Dewey" wrote in message ...
Please help!

I've been trying to send an email from within a COM addin in VB.net 2005,
but keep getting a very weird message:

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

I am trying to send from a form in a COM addin that I open from within
Outlook


Here's the sub I use:
-----------------------------
Private Sub SendMail( )

Dim myOlApp As Outlook._Application
'Dim myOlApp As Object
Dim MyItem As Outlook._MailItem
Dim luvRecipients As Outlook.Recipients
Dim luvRecipient As Outlook.Recipient
myOlApp = New Outlook.Application
'MyItem = myOlApp.CreateItem(OlItemType.olMailItem)
'MyItem.Display()
On Error Resume Next


'this is the body of the email
MyItem.Subject = "Image sending test"
MyItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
MyItem.HTMLBody = "HTMLDIV ALIGN=CENTERIMG
src='\\Fil-nw04-10\hello.jpg/HTML"

MyItem.Send()

End Sub
-----------------------------

Thanks very much for any help in advance!

-Josh


  #4  
Old July 18th 07, 02:46 AM posted to microsoft.public.outlook.program_addins
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Please help! Sending mail from a COM add-in

You can use the article at http://msdn2.microsoft.com/en-us/library/Aa155703.aspx as your guide and use a separate OutAddIn class to expose an Outlook.Application object that all other modules can access.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Dewey" wrote in message ...
Hi Sue

I'm using IDTExtensibility2. However, and excuse my beginner-ness, but I
did think to try passing that object, but it's created in the "OnConnection"
sub in another class. How can I pass it properly to the class with my form
that sends the email...or should I even be taking that route? (Sorry if this
makes no sense...I'm still a very VB6-oriented individual). My old fashoined
and sloppy sense would have me use a global variable, but I'm guessing that's
out here in .net land. Here's where the application object is first exposed
in IDTExtensibility2:



Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection

If (connectMode Extensibility.ext_ConnectMode.ext_cm_Startup)
Then _
Call OnStartupComplete(custom)

olApp = CType(application,
Microsoft.Office.Interop.Outlook.Application)

End Sub ( )



Thank you very much for your help
-Josh



"Sue Mosher [MVP-Outlook]" wrote:

An Outlook add-in should never contain a statement like this:

myOlApp = New Outlook.Application

Instead, you need to be using the Outlook.Application object exposed by the application architecture. Are you using VSTO 2005 SE or IDTExtensibility2?

"Dewey" wrote in message ...
Please help!

I've been trying to send an email from within a COM addin in VB.net 2005,
but keep getting a very weird message:

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

I am trying to send from a form in a COM addin that I open from within
Outlook


Here's the sub I use:
-----------------------------
Private Sub SendMail( )

Dim myOlApp As Outlook._Application
'Dim myOlApp As Object
Dim MyItem As Outlook._MailItem
Dim luvRecipients As Outlook.Recipients
Dim luvRecipient As Outlook.Recipient
myOlApp = New Outlook.Application
'MyItem = myOlApp.CreateItem(OlItemType.olMailItem)
'MyItem.Display()
On Error Resume Next


'this is the body of the email
MyItem.Subject = "Image sending test"
MyItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
MyItem.HTMLBody = "HTMLDIV ALIGN=CENTERIMG
src='\\Fil-nw04-10\hello.jpg/HTML"

MyItem.Send()

End Sub
-----------------------------

Thanks very much for any help in advance!

-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
Saving the mail in sent items without actually sending the mail. Joe Add-ins for Outlook 2 June 7th 07 10:25 PM
post item to mail folder without sending mail John Keith Outlook - General Queries 4 April 26th 07 06:06 AM
Sending mail from NewMailEx deletes the mail from the Inbox Ron Outlook and VBA 1 January 10th 07 08:40 PM
Sending E-Mail Ted Outlook - General Queries 2 September 5th 06 02:39 PM
keeps sending same e-mail Rie Rie Outlook - General Queries 3 March 21st 06 08:14 PM


All times are GMT +1. The time now is 08:49 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.