ComponentPro UltimateMail

      Sending HTML mail

      Language Filter: AllSend comments on this topic to ComponentPro

      UltimateMail makes it easy to create a complete HTML email message with only a few lines of code. To accomplish this, tou can either set the property BodyHtml or call the Load method of the MailMessage class.

      The following example illustrates how to load a HTML file from disk as the body of a mail message and send it:

      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();
          MailMessage msg = new MailMessage();
          msg.Subject = "Test Subject";                
          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));