Solved

How to get delivery reports of emails sent directly from asp.net application using system.net.mail objects?

Posted on 2009-05-03
4
878 Views
Last Modified: 2013-12-17
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.
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

Open in new window

0
Comment
Question by:venkatca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 24290073
are you sure that your host is correctly set? are you sending e-mails to the same domain only?

see http://www.emoreau.com/Entries/Articles/2007/09/Using-SystemNetMail.aspx
0
 
LVL 1

Author Comment

by:venkatca
ID: 24290647
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.
0
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 500 total points
ID: 24392919
Include the following code

Mail_Message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess

You can select multiple options by using bitwise operations.

Mail_Message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess Or DeliveryNotificationOptions.OnFailure Or DeliveryNotificationOptions.Delay
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question