Get Email delivery Success and Failure status in C# and VB.Net

indradeo
 
on Dec 08, 2019 11:31 PM
Sample_122061.zip
2404 Views

how to make mail delivery function using asp c#

i want to mail delivery staus while mail delivered to destination.

 

 

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Dec 09, 2019 04:30 AM

Hi indradeo,

You need to specify the delivery notification options for e-mail.

Refer below code.

Namespaces

C#

using System.Net;
using System.Net.Mail;

VB.Net

Imports System.Net
Imports System.Net.Mail

Code

C#

protected void SendEmail(object sender, EventArgs e)
{
    using (MailMessage mm = new MailMessage("sender@gmail.com", "recipient@gmail.com"))
    {
        mm.Subject = "DataGridView";
        mm.Body = "Test Email.";
        mm.IsBodyHtml = true;
        mm.Priority = MailPriority.High;
        mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
        mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

        NetworkCredential NetworkCred = new NetworkCredential(mm.From.Address, "xxxxxx");
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
    }
}

VB.Net

Protected Sub SendEmail(ByVal sender As Object, ByVal e As EventArgs)
    Using mm As MailMessage = New MailMessage("sender@gmail.com", "recipient@gmail.com")
        mm.Subject = "DataGridView"
        mm.Body = "Test Email."
        mm.IsBodyHtml = True
        mm.Priority = MailPriority.High
        mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess
        mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure

        Dim NetworkCred As NetworkCredential = New NetworkCredential(mm.From.Address, "xxxxxx")
        Dim smtp As SmtpClient = New SmtpClient()
        smtp.Host = "smtp.gmail.com"
        smtp.EnableSsl = True
        smtp.UseDefaultCredentials = True
        smtp.Credentials = NetworkCred
        smtp.Port = 587
        smtp.Send(mm)
    End Using
End Sub

For more details refer below link.

Delivery Notification Options