Guys,

I am intermittently getting a Catastrophic fail error when trying to send e-mail messages through Outlook. I am not seeing this all the time, I cannot tie it down to specific users, mail profiles, machines, servers etc etc. I have posted the exception stack trace below, and also the code/module it seems to be hitting the error in. Has anybody had any experience of this, or can anybody see any issues with my code ?

Like I said, this is intermittent, 75% of the time it is working fine.

Thanks in advance,
Bob

EDIT - I should mention that I am using Outlook Redemption to bypass security messages, but this has never been an issue, its always worked well.

Exception: COMException
Stack Trace:
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at SQLWorkbook.EMail.sendnotification(String docshortname, String savepath, String doclongname, String documentpath)
at SQLWorkbook.uc_MaterialsReceived.btn_save_Click(Object sender, EventArgs e)

VB Code:
  1. Public Sub sendnotification(ByVal docshortname As String, _
  2.      ByVal savepath As String, ByVal doclongname As String, _
  3.      ByVal documentpath As String, ByVal ContractID As String, _
  4.      ByVal Subject As String)
  5.  
  6.         Try
  7.             Dim pdb As PWBdbase.PWBdbase = New PWBdbase.PWBdbase
  8.  
  9.             Dim recipients As String = ""
  10.             Dim dt As DataTable = pdb.ContractStaff.Table(ContractID)
  11.             For Each row As DataRow In dt.Rows
  12.                 If pdb.Nz(row(docshortname.ToString), False) Then
  13.                     recipients &= pdb.Nz(row("Email"), "") & vbTab
  14.                 End If
  15.             Next
  16.             If Right(recipients, 1) = vbTab Then recipients = Left(recipients, Len(recipients) - 1)
  17.             Dim recipientlist() = Split(recipients, vbTab)
  18.             If recipientlist.GetUpperBound(0) = -1 Then Return
  19.  
  20.             Dim appOutlook As Object
  21.             Dim mi As Object
  22.             Dim Created As Boolean
  23.             Dim safeitem As Object
  24.             Dim olMailItem As Object
  25.  
  26.             'Generate mail item
  27.             Dim myOlApp = CreateObject("Outlook.Application")
  28.             Dim myNameSpace = myOlApp.GetNamespace("MAPI")
  29.             myNameSpace.Logon()
  30.             safeitem = CreateObject("Redemption.SafeMailItem")
  31.             mi = myOlApp.CreateItem(olMailItem)
  32.             safeitem.Item = mi
  33.             'mi.Display
  34.             If Created Then appOutlook.Quit()
  35.  
  36.             Dim recipientsadded As Boolean = False
  37.             For Each recipient As String In recipientlist
  38.                 If Not recipient = "" Then
  39.                     safeitem.Recipients.Add(recipient)
  40.                     recipientsadded = True
  41.                 End If
  42.             Next
  43.  
  44.             If recipientsadded Then
  45.                 'Get info and send mail
  46.                 With safeitem.Item
  47.                     .subject = Subject & " - PWB Automatic Notification"
  48.                     .HTMLBody = "This message has been generated automatically." & "<br>" & _
  49.                     "A new " & doclongname & " has been created for this Contract." & "<br>" & "<br>" & _
  50.                     "Please click this link to goto the folder." & "<br>" & _
  51.                     "<a href=" & Chr(34) & savepath & Chr(34) & ">" & savepath & "</a>" & "<br>" & "<br>" & _
  52.                     "Or click this link to open the new document." & "<br>" & _
  53.                     "<a href=" & Chr(34) & documentpath & Chr(34) & ">" & documentpath & "</a>"
  54.                 End With
  55.                 safeitem.send()
  56.             End If
  57.  
  58.             mi = Nothing
  59.             If Created Then appOutlook.Quit()
  60.             appOutlook = Nothing
  61.             dt.Dispose()
  62.             dt = Nothing
  63.             recipientsadded = Nothing
  64.             recipientlist = Nothing
  65.  
  66.         Catch ex As Exception
  67.            eh.log(ex)
  68.         End Try
  69.  
  70.  
  71.     End Sub