Results 1 to 3 of 3

Thread: [RESOLVED] [Outlook 2010 & VS2008] Create email with AutoSig

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2012
    Posts
    17

    Resolved [RESOLVED] [Outlook 2010 & VS2008] Create email with AutoSig

    Hi,

    I'm fairly new to the world of forums (& coding) so please bear with me if I fail on ettiquette.

    I've searched the forums and the oracle & found a few posts that are similar to the issue I'm having but none of the advised fixes have proved successfull.(re-installing PIA's, re-registering just about every .dll & .ocx ever created)

    I'm sure that I've missed something very simple on this but I've been at it for 3 days now and for the life of me I cannot figure it out.

    When running the code below, I get the following error:

    Unable to cast COM object of type
    'Microsoft.Office.Interop.Outlook.InspectorClass' to interface type
    'Microsoft.Office.Interop.Outlook.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID
    '{00063001-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRRESULT: 0x80004002 (E_NOINTERFACE)).

    Background:
    • Recently upgraded from VS2005 & MsO2007 to VS2008 & MsO2010

    • .NET conversion worked without (reported) error


    Code snippet:

    Code:
    Imports System
    Imports System.IO
    Imports System.Management
    Imports System.Runtime.InteropServices
    Imports Microsoft.Office.Interop.Outlook
    
    Dim oMailApp As Interop.Outlook.Application
    Dim oNS As Interop.Outlook.NameSpace = Nothing
    Dim oFolder As Interop.Outlook.MAPIFolder = Nothing
    Dim oFolderItems As Interop.Outlook.Items = Nothing
    Dim oMail As Interop.Outlook.MailItem = Nothing
    Dim oMailMoved As Interop.Outlook.MailItem = Nothing
    
    Try
        oMailApp = New Interop.Outlook.Application
        oNS = oMailApp.GetNamespace("MAPI")
        oFolder = oNS.GetDefaultFolder(Interop.Outlook.OlDefaultFolders.olFolderDrafts)
        oFolderItems = oFolder.Items
        oMail = oFolderItems.Add(Interop.Outlook.OlItemType.olMailItem)
        oMailApp = oMail.GetInspector
        
        If LCase(sPC) = "not known" Then
            oMail.To = "anemailaddress"
        Else
            oMail.To = "anemailaddress"
            oMail.CC = "anemailaddress"
        End If
        
        oMail.Subject = "A Subject"
        oMail.BodyFormat = Interop.Outlook.OlBodyFormat.olFormatHTML
        oMail.HTMLBody = "Some body text"
        oMail.Importance = Interop.Outlook.OlImportance.olImportanceHigh
        oMail.UnRead = True
        ' Move the item to Inbox and then save it there   
        oMailMoved = oMail.Move(oFolder)
        oMailMoved.Save()
        oMailMoved.Display(True)
    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    Finally
        If Not IsNothing(oMailMoved) Then Marshal.ReleaseComObject(oMailMoved)
        If Not IsNothing(oMail) Then Marshal.ReleaseComObject(oMail)
        If Not IsNothing(oFolderItems) Then Marshal.ReleaseComObject(oFolderItems)
        If Not IsNothing(oFolder) Then Marshal.ReleaseComObject(oFolder)
        If Not IsNothing(oNS) Then Marshal.ReleaseComObject(oNS)
    End Try
    A couple of other points:
    • Could this be anything to do with the fact the project location is not trusted?

    • Under VS2005 the Microsoft.Office.Tools.Outlook namespace was imported, I can't seem to be able to find a reference to this to add to the project but seeing as it's not used (directly) I'm not sure if this matters either.


    Any help would be hugely appreciated.

    Many thanks

    Lex.
    Last edited by LexGixxer; Feb 8th, 2012 at 02:07 PM. Reason: Removed pointless screenshot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width