I have the below code to send emails from my application. Problem is I'm not 100% sure they are making it to the all the clients. How do I add some code to confirm the delivary or non-delivary of the emails.
Thanks for any help provided..
Public Function getAD(ByVal bnumber As String) As String
Dim Email As String = ""
Try
Dim strLdap As String = "LDAP://bbtnet.com"
Dim objDirEntry As New DirectoryEntry(strLdap)
Dim dirSearcher As New DirectorySearcher(objDirEntry)
dirSearcher.Filter = "(cn=" & bnumber & ")"
Dim results As SearchResultCollection
results = dirSearcher.FindAll()
Dim PropCollection As ResultPropertyCollection = Nothing
For Each i As SearchResult In results
PropCollection = i.Properties
Next
For Each strKey As String In PropCollection.PropertyNames
If strKey.ToString = "mail" Then
For Each objProperty As Object In PropCollection(strKey)
Email = objProperty.ToString
Exit For
Next
End If
Next
results.Dispose()
dirSearcher.Dispose()
objDirEntry.Dispose()
objDirEntry.Close()
' if the email is empty that means the bnumber doesn't exist
If Email = Nothing Then
Throw New ArgumentException("The bnumber: " & bnumber & " was not found.")
End If
Catch ex As ArgumentException
ReportError(ex.Message, "CLCS Conversion - Active Directory")
Catch ex As Exception
ReportError(ex.Message, "CLCS Conversion - Active Directory")
End Try
Return Email
End Function
2. This is to send the email
' routing email sub
Public Sub EmailRoute(ByVal m As String, _
ByVal subject As String, _
ByVal fromemail As String, _
ByVal email As String)
Dim message As New MailMessage("CLCS Loan Operations <CLCS.LoanOperations@email.com>", email)
message.Subject = subject
Dim text As String = "<FONT size='3' color='red'><b>** Please Do Not Reply To This Email Account **</b></font><br>"
text &= "<FONT color='red'>This message was generated automatically.</font><br><br>"
message.Body = "<html><head><title>" & subject & "</title></head><body>" & text & m & "</body></html>"
'message.CC.Add(copy)
message.IsBodyHtml = True
message.Priority = MailPriority.Normal
Dim smtpclient As New SmtpClient("clt-exmb01.bbtcnet.com")
Try
smtpclient.Send(message)
Catch ex As Exception
ReportError(ex.Message, "EMAIL ROUTING")
End Try
message.Dispose()
End Sub
Thanks,
Thanks for any help provided..
Public Function getAD(ByVal bnumber As String) As String
Dim Email As String = ""
Try
Dim strLdap As String = "LDAP://bbtnet.com"
Dim objDirEntry As New DirectoryEntry(strLdap)
Dim dirSearcher As New DirectorySearcher(objDirEntry)
dirSearcher.Filter = "(cn=" & bnumber & ")"
Dim results As SearchResultCollection
results = dirSearcher.FindAll()
Dim PropCollection As ResultPropertyCollection = Nothing
For Each i As SearchResult In results
PropCollection = i.Properties
Next
For Each strKey As String In PropCollection.PropertyNames
If strKey.ToString = "mail" Then
For Each objProperty As Object In PropCollection(strKey)
Email = objProperty.ToString
Exit For
Next
End If
Next
results.Dispose()
dirSearcher.Dispose()
objDirEntry.Dispose()
objDirEntry.Close()
' if the email is empty that means the bnumber doesn't exist
If Email = Nothing Then
Throw New ArgumentException("The bnumber: " & bnumber & " was not found.")
End If
Catch ex As ArgumentException
ReportError(ex.Message, "CLCS Conversion - Active Directory")
Catch ex As Exception
ReportError(ex.Message, "CLCS Conversion - Active Directory")
End Try
Return Email
End Function
2. This is to send the email
' routing email sub
Public Sub EmailRoute(ByVal m As String, _
ByVal subject As String, _
ByVal fromemail As String, _
ByVal email As String)
Dim message As New MailMessage("CLCS Loan Operations <CLCS.LoanOperations@email.com>", email)
message.Subject = subject
Dim text As String = "<FONT size='3' color='red'><b>** Please Do Not Reply To This Email Account **</b></font><br>"
text &= "<FONT color='red'>This message was generated automatically.</font><br><br>"
message.Body = "<html><head><title>" & subject & "</title></head><body>" & text & m & "</body></html>"
'message.CC.Add(copy)
message.IsBodyHtml = True
message.Priority = MailPriority.Normal
Dim smtpclient As New SmtpClient("clt-exmb01.bbtcnet.com")
Try
smtpclient.Send(message)
Catch ex As Exception
ReportError(ex.Message, "EMAIL ROUTING")
End Try
message.Dispose()
End Sub
Thanks,