Link to home
Start Free TrialLog in
Avatar of Chuck Wood
Chuck WoodFlag for United States of America

asked on

Error Using Outlook in VB.Net

I have code that was working until about three days ago.
    Public Function Email(ByVal strTo As String, ByVal strSubject As String, _
      ByVal strBody As String, Optional ByVal strCC As String = "", Optional ByVal strAttachment As String = "", _
      Optional ByVal fDeliveryReq As Boolean = False, Optional ByVal fReadRecpt As Boolean = False) As Boolean
        Email = False
        Dim olMailItem As Int16, olImportanceHigh As Int16
        olMailItem = 0
        olImportanceHigh = 2
        ' set the initial state of the function
        Email = False
        Dim outl As New Outlook.Application, intI As Integer
        ' create an email item
        Dim outMsg As Outlook.MailItem
        outMsg = outl.CreateItem(olMailItem)
        With outMsg
            ' set the message parts
            .To = strTo
            .Subject = strSubject
            .Body = strBody
            .CC = strCC
            .Importance = olImportanceHigh
            .OriginatorDeliveryReportRequested = fDeliveryReq
            .ReadReceiptRequested = fReadRecpt
            ' send the message
            ' set the final state of the function
            Email = True
        End With
    End Function
End Module

When this code is run, it errors at "Dim outl As New Outlook.Application" with this error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in CSIDTest.exe
Additional information: The RPC server is unavailable.

I am using VB.Net in Visual Stuio 2003. I have a reference to the Microsoft Outlook 9.0 Object Library.
Again, this code worked perfectly until recently.

What is causing this error?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Did you apply any service packs, hot fixes, etc.?

Avatar of Chuck Wood


I didn't. And our corporate IT has not anounced any.
1) What is the application context for that method?  Where it called from?  How many times is it called?  

2) Are you having problems with the first time or any subsequent call?

Hi Bob,

It is called from the Main procedure when a Try (checking a database on a server) fails and the method is is called from the Catch. It will only be called once in any run of the console application, which runs once every two minutes.

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial