Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email delivary confirmation

Status
Not open for further replies.

ecugrad

MIS
Apr 17, 2001
191
US
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,



 
before I get to the actual question I want to point out there is a major flaw with your error handling. you are simply logging the message, but you are loosing everything else, the type of error, and the most importantly, the stack trace. i would recommend either passing the entire error to the ReportError method, or pass exception.ToString(). the ToString() method of exception will create a string including the error type, message and stack trace.

the smtp client in .net is fire and forget. you can find out if an error occurred while contacting the email server, but once it notifies the email server, it's done.

you can add headers and other items to the mail message. and these headers may be interpreted by the email server or user's email client, but .net itself doesn't have any knowledge of what these headers do. for more information on system.net.mail check out
Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top