Announcement

Collapse
No announcement yet.

Outlook Versand Emails - Unable to cast object of type 'System.__ComObject' to type '

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Outlook Versand Emails - Unable to cast object of type 'System.__ComObject' to type '

    Umgebung: VS 2010 /VB - Projekt -> Windows Forms
    Outlook 2003

    Bei dem automatischen Versand von Emails bekomme ich denfolgenden Fehler:

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


    Folgender Quellcode:
    Code:
    Public Shared Sub SendEmailFromAccount(ByVal subject As String, ByVal body As String, ByVal recipients As String, ByVal smtpAddress As String, ByVal attm() As String, ByVal count_attm As Integer, Optional ByVal flag_display_send As String = "D")
            Try
    
                Dim objOutlook As New Outlook.Application
              
                objOutlook.CreateObject("Outlook.Application")
                Dim objOutlookMsg As Outlook.MailItem
              
                ' === objOutlookMsg = objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
                objOutlookMsg = objOutlook.CreateItem(0)
                With objOutlookMsg
                    .To = recipients
                    .CC = ""               
                    .BCC = ""               
                    .Subject = subject               
                    .Body = body               
                    'Attachment erstellen
                    If count_attm > 0 Then
                        For i = 0 To count_attm - 1
                            objOutlookMsg.Attachments.Add(attm(i))
                        Next
                    End If
                   
             
                    Select Case flag_display_send
                        Case "D"
                            '//am Bildschirm anzeigen
                            .Display()
                        Case "S"
                            .Send()
                            If debugshow = "Y" Then MsgBox(" send")
                    End Select
    
                End With
                'objOutlook = Nothing
            Catch ex As Exception
                tools.show_errors(ex, "mailtool_func", "SendEmailFromAccount")
                'MsgBox(Err.Number & " " & Err.Description)
                globfunction.write_log("Error (" & mailtyp & "/" & subject & "/" & recipients & "): " & Err.Number & " " & Err.Description, logfile)
            End Try
        End Sub
    Kann mir jemand einen Tipp geben, was ich falsch mache? Danke schon mal

  • #2
    Hallo alle zusammen,

    ich habe wohl das Sommerloch erwischt. Ok, aber ich habe den Code nochmal umgestellt und nun tritt der Fehler nicht mehr auf.

    Code:
                Dim objOutlook As Outlook.Application
                ' Dim objOutlook As new Outlook.Application  20130801 raus 
                objOutlook = GetObject(, "Outlook.Application") ' rein
    Nur zur Kenntnis. Und sollte doch noch jemand eine bessere Idee haben, dann bitte und danke.

    mfg dbfreak

    Comment


    • #3
      CreateObject ist vermutlich richtiger als GetObject. GetObject verbindet sich zu einer laufenden Outlook Instanz. Wenn bei deinem Code Outlook nicht bereits läuft sollte es eigentlich knallen.

      Comment


      • #4
        Hallo R. Jansen,

        danke. Ja, das ist mir klar. Drum prüfe ich vorher, ob Outlook gestartet ist und starte es ggf.
        Hast Du eine Idee zu dem Fehler? Im Google habe ich Einträge gefunden, wonach man in der Registry editieren soll. Hat mir ehrlich gesagt nicht gefallen. Es ist ein Kundenrechner.

        mfg dbfreak

        Comment

        Working...
        X