ComponentPro UltimateMail

      Sending mail with Delivery Status Notification (DSN)

      Language Filter: AllSend comments on this topic to ComponentPro

      Delivery status notification (DSN) is an extension added to SMTP to extend the types of and situations when the sender will be notified of the status of a send message. The DSN is represented by the enumerate DeliveryStatusNotificationType and accessible via the DeliveryStatusNotificationType property of the Smtp class.

      The example below demonstrates how to use DSN:

      using System;
      using System.Windows.Forms;
      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      const string serverName = "myserver";
      const string user = "";
      const string password = "mytestpassword";
      const int port = 465;
      const SslSecurityMode securityMode = SslSecurityMode.Implicit;
      Smtp client = new Smtp();
      // Return message on failure.
      client.DeliveryStatusNotificationType = DeliveryStatusNotificationType.Failure;
      // Return message on success. 
      //client.DeliveryStatusNotificationType = DeliveryStatusNotificationType.OnSuccess; 
      // And return full message.
      client.DeliveryStatusNotificationReturnMessageMethod = DeliveryStatusNotificationReturnMessageMethod.FullMessage;
          MailMessage msg = new MailMessage();
          msg.Subject = "Test Subject";
          msg.BodyText = "Test Content";
          Console.WriteLine("Connecting SMTP server: {0}:{1}...", serverName, port);
          // Connect to the server. 
          client.Connect(serverName, port, securityMode);
          // Login to the server. 
          Console.WriteLine("Logging in as {0}...", user);
          client.Authenticate(user, password);
          Console.WriteLine("Sending message...");
          Console.WriteLine("Message sent...");
          // Disconnect. 
      catch (SmtpException smtpExc)
          MessageBox.Show(string.Format("An SMTP error occurred: {0}, ErrorStatus: {1}", smtpExc.Message, smtpExc.Status));
      catch (Exception exc)
          MessageBox.Show(string.Format("An error occurred: {0}", exc.Message));