COM Interop Problem - [CDO - [MAPI_E_UNCONFIGURED(8004011C)]]

Discussion in 'ASP .Net Security' started by Chris V, Jan 21, 2004.

  1. Chris V

    Chris V Guest

    Hello,

    I'm having problems sending MAPI Mail from an ASP.NET applcation (in VB)
    (which worked fine in traditional asp)

    When run on our test server, it returns an COMException (0x80010106):
    [Collaboration Data Objects - [UNKNOWN_ERROR(80010106)]]] exception from
    MAPI.
    (from the global.asa when trying to create MAPI session I get a .net
    exception "Cannot change thread mode after it is set")

    According to a post on the microsoft.public.in.csharp

    "The 80010106 error usually occurs due to incompatible
    threading models. ASP.NET uses an MTA thread pool
    to service requests for the web service and looks like
    the CDO component is apartment threaded (lives in an STA).

    In traditional ASPX pages, you'd use the ASPCOMPAT
    attribute set to true in the <%@ Page %> directive of an
    ASPX page to make a ASP.NET use an STA thread
    (instead of an MTA thread) to access the apartment threaded
    COM component."

    So I set the ASPCOMPAT attribute of the aspx page that calls this method to
    "true".

    This now appears to create the object correctly.

    But returns a new error.
    [Collaboration Data Objects - [MAPI_E_UNCONFIGURED(8004011C)]]

    I think this may be due to the identity of the STA MAPI Component, being
    different from the impersonated ASP.NET user in the Web.config file, but i'm
    not sure.

    >>> Does anyone know....


    a) How I can confirm this is the case?
    b) Ensure that the MAPI component is running under the same identity?

    I have included below the original legacy code from the traditional asp
    application and the new COM Interop code from the ASP.NET version of my
    application.

    Any suggestions are welcome! particularly code examples ;-)

    thank you very much.

    Chris V.


    '--------------------------------original mail.inc used in asp page
    (works).----------------------------------------
    Dim oSession
    Set oSession = CreateObject("MAPI.Session")

    oSession.Logon "", "", False, True, 0, True,
    Application("ExchangeServerLocation") & vblf &
    Application("ExchangeServerMailbox")

    Dim oOutbox
    Set oOutbox = oSession.Outbox

    Dim oMessage
    Set oMessage = oOutbox.Messages.Add
    oMessage.Subject = Subject
    oMessage.Text = Body

    Dim oRecipient

    For i = 0 To oVec.Count - 1


    Set oRecipient = oMessage.Recipients.Add
    oRecipient.Name = oVec(i)
    oRecipient.Resolve
    Set oRecipient = Nothing

    Next

    oMessage.Send



    oSession.Logoff

    Set oMessage = Nothing
    Set oOutbox = Nothing
    Set oSession = Nothing

    '-----------------MAPIMESSAGE.VB (called from test.aspx with aspcompat set
    to true.)-----------------------

    Imports Microsoft.Office.Interop
    Imports MAPI

    Public Class MAPIMail
    Implements IQPWMessageSender

    Private mExchangeServer As String
    Private mMailbox As String

    Public Sub New(ByVal MAPIExchangeServer As String, ByVal MAPIMailbox As
    String)
    mExchangeServer = MAPIExchangeServer
    mMailbox = MAPIMailbox
    End Sub

    Public Function SendMail(ByVal CommaDelimitedRecipients As String, _
    ByVal Subject As String, ByVal Body As String) As Boolean Implements
    IQPWMessageSender.SendMail

    Dim recipients As String()

    Dim oSession As New MAPI.Session
    oSession.Logon("", "", False, True, 0, True, mExchangeServer & vbLf
    & mMailbox)

    Dim oOutbox As Object
    oOutbox = oSession.Outbox

    Dim oMessage As MAPI.Message

    oMessage = oOutbox.Messages.Add
    oMessage.Subject = Subject
    oMessage.Text = Body

    Dim oRecipient As Object

    recipients =
    QPWDataHelper.CSVToStringArray(CommaDelimitedRecipients)
    recipients = QPWMessage.RemoveDups(recipients)

    Dim recip As String
    For Each recip In recipients
    If Trim(recip) <> "" Then
    oRecipient = oMessage.Recipients.Add
    oRecipient.Name = Trim(recip.ToString)
    oRecipient.Resolve()
    oRecipient = Nothing
    End If
    Next

    If recipients.Length > 0 Then
    Try
    oMessage.Send()
    Catch ex As Exception
    QPWLog.WriteToLog("Mapi error" & ex.Message)
    End Try
    Else
    QPWLog.WriteToLog("Did not send MAPI message as there were no
    recipients.")
    End If

    oSession.Logoff()

    oMessage = Nothing
    oOutbox = Nothing
    oSession = Nothing

    End Function

    End Class
    '--------------------------------------
     
    Chris V, Jan 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    884
    dave wanta
    Jul 11, 2003
  2. Andrew Connell
    Replies:
    3
    Views:
    2,795
    Andrew Connell
    Oct 22, 2003
  3. Chris V
    Replies:
    0
    Views:
    2,286
    Chris V
    Jan 21, 2004
  4. =?Utf-8?B?VUtQb3N0aWU=?=

    COM Interop problem with 3rd Party DLL using C# under ASP.NET

    =?Utf-8?B?VUtQb3N0aWU=?=, Sep 23, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    814
    =?Utf-8?B?VUtQb3N0aWU=?=
    Sep 23, 2004
  5. Replies:
    0
    Views:
    283
Loading...

Share This Page