![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |