ComponentPro UltimateMail

      Sending mail message to multiple recipients

      Language Filter: AllSend comments on this topic to ComponentPro

      You may have to send an email message to multiple recipients. UltimateMail makes sending to multiple recipients easy to manage, by representing these types as collections of the MailMessage object.

      The example below illustrates how to send a mail message to multiple recipients:

      using System;
      using System.Windows.Forms;
      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      
      ...
      
      const string serverName = "myserver";
      const string user = "name@domain.com";
      const string password = "mytestpassword";
      const int port = 465;
      const SslSecurityMode securityMode = SslSecurityMode.Implicit;
      
      Smtp client = new Smtp();
      try
      {
          MailMessage mmMessage = new MailMessage();
          mmMessage.From.Add("from@thedomain.com");
          mmMessage.To.Add("name@domain.com");
          mmMessage.To.Add("someone@domain.com");
          mmMessage.CC.Add("someone2@domain.com");
          mmMessage.Bcc.Add("someone3@domain.com");
          mmMessage.Subject = "Test Subject";
          mmMessage.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 mail message...");
          client.Send(mmMessage);
          Console.WriteLine("Message sent...");
      
          // Disconnect. 
          Console.WriteLine("Disconnecting...");
          client.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));
      }