I want to get the delivery notification after sending a mail whether is was success or failure, on google I got to know about DeliveryNotificationOptions
, but when i tried to create one poc to check this I am not getting proper answer.
class Program
{
static string smtpAddress = "smtp.gmail.com";
static int portNumber = 587;
static bool enableSSL = true;
static string emailFromAddress = "[email protected]"; //Sender Email Address
static string password = "password"; //Sender Password
static string emailToAddress = "[email protected]"; //Receiver Email Address
static string subject = "Hello";
static string body = "Hello, This is Email sending test using gmail.";
static void Main(string[] args)
{
SendEmail();
}
public static void SendEmail()
{
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFromAddress);
mail.To.Add(emailToAddress);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
//mail.Attachments.Add(new Attachment("D:\\TestFile.txt"));//--Uncomment this to send any attachment
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFromAddress, password);
smtp.EnableSsl = enableSSL;
mail.Headers.Add("Disposition-Notification-To", emailToAddress);
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
smtp.Send(mail);
}
}
}
}
On output I am getting success even though the from email is wrong. Can someone please help me to explain how can I achieve this scenario.
Thanks, Shreya
I also found different workaround using ASPNETMX , you can find Licence-key, Code example and Dll on that site
}