ComponentPro UltimateMail

      Sending mail directly without SMTP server

      Language Filter: AllSend comments on this topic to ComponentPro

      In some scenarios, your SMTP server is either not available or you want to directly send a message to the specified addresses. In this case, you can use the SendDirect method to directly send the message. The target SMTP server address is determined by asking the DNS system for MX records of the target domain, all are done by the UltimateMail component and you don't have to care about it. But firstly, you have to make sure that the SMTP port 25 is allowed for the direct connections to the remote SMTP servers, and the DNS subsystem must be working. See the following example for more details:

      using System;
      using System.Windows.Forms;
      using ComponentPro.Net.Mail;
      
      ...
      
      try
      {
          MailMessage msg = new MailMessage();
          msg.From.Add("from@thedomain.com");
          msg.To.Add("name@domain.com");
          msg.Subject = "Test Subject";
          msg.BodyText = "Test Content";
      
          Console.WriteLine("Sending a message directly...");
          Smtp.SendDirect(msg);
          Console.WriteLine("Message sent...");
      }
      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));
      }