venkatca
asked on
How to get delivery reports of emails sent directly from asp.net application using system.net.mail objects?
We are sending auto emails from our asp.net application using system.net.mail objects. Whenever the sent email id is invalid, the mail resides in inetpub\mailroot\badmail folder. Is there any way that the application can track this as soon as the mail is sent and inform the user accordingly that this email has not been delivered.
Sample code being used for sending emails attached below.
Sample code being used for sending emails attached below.
Public Function SendEmail(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strMsg As String, ByVal attchemnt As String) As Boolean
Dim Mail_Message As New MailMessage
Dim FromAddress As New MailAddress(strFrom)
Dim msClient As New SmtpClient
Try
'Set From Email id
Mail_Message.From = FromAddress
'Set To Email id
Mail_Message.To.Add(strTo)
'Set Subject
Mail_Message.Subject = strSubject
'Set Msg Body
Mail_Message.Body = strMsg
Mail_Message.Priority = MailPriority.Normal
Mail_Message.IsBodyHtml = True
Mail_Message.Attachments.Add(New Attachment(attchemnt))
msClient.Port = 25
msClient.Host = "127.0.0.1"
msClient.Send(Mail_Message)
Mail_Message.Dispose()
SendEmail = True
Catch ex As Exception
Mail_Message.Dispose()
SendEmail = False
End Try
End Function
ASKER
Yes the host is correctly set on the production server. The code I have attached above is for development server that is why 127.0.0.1.
We are not sending emails to the same domain only, we are sending to all external email ids. For eg, whenever a guest completes a hotel booking, the application will send him an email with the confirmation and hotel voucher.
Currently the emails are sending fine, the only issue is of knowing which ones did not go through due to incorrect email ids or mail box being full etc which normally is given in delivery reports.
We are not sending emails to the same domain only, we are sending to all external email ids. For eg, whenever a guest completes a hotel booking, the application will send him an email with the confirmation and hotel voucher.
Currently the emails are sending fine, the only issue is of knowing which ones did not go through due to incorrect email ids or mail box being full etc which normally is given in delivery reports.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
see http://www.emoreau.com/Entries/Articles/2007/09/Using-SystemNetMail.aspx