Does anyone know how to confirm if an email was sent successfully?

I’m using the new System.Net.Mail.MailMessage to send emails and will like to have a way to confirm if sent ok. (I have no problems sending, I just need the confirmation only)

< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

Which function or method to use Can anyone post a snippet for this

Thanks all



Answer this question

Does anyone know how to confirm if an email was sent successfully?

  • Seshu Palachulla

    What exactlty is the version of the framework and Visual Studio you are using

  • Phan

    You don't need to wait.

    The .NET 2.0 Redist (framework) and sdk are free :-)
    and the SDK is also free. Download, and just set the path to the
    VBC compiler and you are good to go. You can easily develop the apps
    with just a good editor and fx/sdk

    Try http://msdn.microsoft.com/net

     



  • mateenashraf

    Hey Durgaprasad Gortion,
     
    Could you try something for me reguarding the DeliveryNotificationOptions...

    I've successfully been able to impliment the option and get a Delivery Receipt.

    Though if I send more then one message I only get the Delivery receipt for the first message sent.

    Any subsequent message does not get a delivery receipt. 

    The Connection to the SMTP Server stays connected even after the SMTPClient & MailMessage Objects go out of scope and a Manual Garbage Collections Happens.  I'm guessing this is to allow multiple messages to be send without opening and closing the SMTP connection each time.

    Though It seems that I only get the one Delivery Receipt for the Connected Session.

    I ran a Protocol Trace and Noted the on the RCPT TO Command sent to the SMTP Server only had the NOTIFY=STATUS for the First message. All the others did not have it.

    Could you Verify this   I could send you my Test app if you like. I've included the Code of my SendEmail Function

    Thanks,
      Scott<-


    Imports System.Net.Mail

    Public Class Form1

    Dim bDebug As Boolean

    Dim intEmailStatus As Integer

    '----------------------------------------------------

    ' Function : fSend_Email()

    ' Returns: Integer

    ' -1 - No From Address

    ' -2 - No To Address

    '----------------------------------------------------

    Protected Function fSend_Email(ByVal strFrom As String, ByVal strFrom_Name As String, ByVal strTo As String, ByVal strCC As String, ByVal strBCC As String, ByVal strSubject As String, ByVal strBody As String, ByVal bIsHTML As Boolean, ByVal iDelivery_Receipt As Int16) As Integer

    Dim intStatus As Integer = 0

    Dim toAddress, fromAddress, ccAddress, bccAddress As MailAddress

    Dim eMail As MailMessage = New MailMessage()

    Dim htmlType As System.Net.Mime.ContentType = New System.Net.Mime.ContentType("text/html")

    If Not String.IsNullOrEmpty(strCC) Then

    ccAddress = New MailAddress(strCC, strCC)

    eMail.CC.Add(ccAddress)

    End If

    If Not String.IsNullOrEmpty(strBCC) Then

    bccAddress = New MailAddress(strBCC, strBCC)

    eMail.Bcc.Add(bccAddress)

    End If

    If Not String.IsNullOrEmpty(strTo) Then

    toAddress = New MailAddress(strTo, strTo)

    eMail.To.Add(toAddress)

    Else

    intStatus = -2

    End If

    If Not String.IsNullOrEmpty(strFrom) Then

    If intStatus = 0 Then

    fromAddress = New MailAddress(strFrom, strFrom_Name)

    eMail.From = fromAddress

    eMail.Subject = strSubject

    eMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess

    'eMail.Headers.Add("Disposition-Notification-To", """" & strFrom_Name & """ <" & strFrom & ">")

    If bIsHTML Then

    eMail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(strBody, htmlType))

    Else

    eMail.Body = strBody

    End If

    Dim client As SmtpClient = New SmtpClient(tbSMTPServer.Text)

    client.Send(eMail)

    client = Nothing

    End If

    Else

    intStatus = -1

    End If

    htmlType = Nothing

    eMail.Dispose()

    System.GC.Collect()

    fSend_Email = intStatus

    End Function

     

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

    intEmailStatus = fSend_Email(tbFrom.Text, tbFrom.Text, tbTo.Text, tbCC.Text, tbBCC.Text, tbSubject.Text, rtbMessage.Text, False, 14)

    End Sub


  • cgruenzner

    Thanks for all your wonderful help. I will come back to this issue after I receive my VS2005 Pro version.

    Thanks again

  • Sam Lowry139354

    Oh, forgot to mention I'm using
    VS2005 8.0.50727.42 (RTM.050727-4200)
    .NET Framework 2.0.50727

    Thanks,
     Scott<-

  • Sergio Silva

    [Flags]

    public enum DeliveryNotificationOptions {

    None = 0, OnSuccess = 1, OnFailure = 2, Delay = 4, Never = (int)0x08000000

    }

    please try the

    DeliveryNotificationOptions property on the MailMessage



  • Praxy

    Durgaprasad:

    Thanks for your patient.

    Since I have not gotten the Visual Studio 2005 Proffessional version I ordered from Amazon I'm still using the Beta #2.


  • Pachacutec

    Durgaprasad Gorti :

    Sorry for the newbie question:

    But how would you use these enums in VB2005 for setting a boolean variable to True if sent OK and false if otherwise

    Thanks


  • Martin Platt

    Its an enum

    So set MailMessage.Deliver.... = Deliver...Success



  • tom-b

    Imports System.Net

    Imports System.Net.Mail

    Module Module1

    Sub Main()

    Dim msg As New MailMessage

    Dim client As New SmtpClient("smtpserver")

    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess

    msg.To.Add(New MailAddress("x@y.com"))

    msg.From = New MailAddress("x@y.com")

    msg.Subject = "test"

    msg.Body = "Test"

    client.UseDefaultCredentials = True 'Optional

    client.Send(msg)

    End Sub

    End Module



  • TGAR

    No matter how hard I try intellisense will simply refuse to to show any of these

    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess


    I paste this code in a module and could not get anything resembling "DeliveryNotificationOptions" in Intellisense after typing msg.

    this is the code:

    Imports System.Net

    Imports System.Net.Mail

    Module Module1

    Sub Main()

    Dim msg As New MailMessage

    Dim client As New SmtpClient("smtpserver")

    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess

    'msg.To.Add(New MailAddr...

    End Sub

    End Module




     


  • frozennose

    Sorry for my stupidity I just don't get it.

    What do you mean by this:

    So set MailMessage.Deliver.... = Deliver...Success

    Intellisense is not giving me any member of this type : MailMessage.Deliver


  • Leo Fi

    I belive this is added post Beta2.
    So no wonder you are not seeing this in intellisense

    Use the VS2005 RTM bits or just use the free redistributables and sdk.



  • Does anyone know how to confirm if an email was sent successfully?