Smtp.NET 3 Documentation

SmtpServer.RandomObject Property

An object of class Random that is used to ensure uniqueness with Smtp.NET and emailQ.NET queueing. Specifically important if using Smtp.NET in a multithreaded environment.

[Visual Basic]
Public Property RandomObject As Random
[C#]
public System.Random RandomObject {get; set;}

Property Value

An object of type Random. The default value is null.

Remarks

If you are creating Smtp.NET objects in multiple threads, it is suggested that you create a Random object in your calling program and pass it to this property. This property only affects messages that are sent to the Queue or Pickup Directory.

Example

[C#]
            public void Send()
            {
                 SmtpServer oSmtpDotNet = new SmtpServer();
             
                 // Set the remote server name.  If left blank, "localhost" is used.
                 oSmtpDotNet.ServerAddress = "mail.domain.com"
                 
                 // Message Addressing
                 oSmtpDotNet.ToAddress = "to@domain.com";
                 oSmtpDotNet.FromAddress = "from@domain.com";
             
                 // Set the message subject and body
                 oSmtpDotNet.Body = "This is the message";
                 oSmtpDotNet.Subject = "Routine email";
                 
                 // Send Messages to the Queue Directory
                 oSmtpDotNet.SendToPickupDirectory = true;
                 oSmtpDotNet.QueueDirectory = "C:\\temp\\emailQ";
                 // Set the Random object to maintain uniqueness with files
                 // created for queuing.
                 oSmtpDotNet.RandomObject = new Random();
                 
                 // Force the message body to be html
                 oSmtpDotNet.BodyFormat = BodyFormatTypes.HTML;
                  
                 ReturnCodes nRC = oSmtpDotNet.Send();
                 if ( nRC != ReturnCodes.SUCCESS )
                 {
                      Console.WriteLine("Error #"+nRC+" occurred.");
                      Console.WriteLine(oSmtpDotNet.LastError);
                      Console.Write(oSmtpDotNet.LogFileToString(false));
                      return;
                 }
             
                 // Success!
                 Console.WriteLine("Success!");
            }
            
[VB]
            Public Function Send() As Integer
                 Dim oSmtpDotNet As New SmtpServer()
                 Dim nRC As ReturnCodes
            
                 ' Set the remote server name.  If left blank, "localhost" is used.
                 oSmtpDotNet.ServerAddress = "mail.domain.com"
                 
                 ' Message Addressing
                 oSmtpDotNet.FromAddress = "from@domain.com"
                 oSmtpDotNet.ToAddress = "to@domain.com"
                 
                 ' Set the message subject and body
                 oSmtpDotNet.Body = "This is the message"
                 oSmtpDotNet.Subject = "Routine email"
                 
                 ' Send Messages to the Queue Directory
                 oSmtpDotNet.SendToPickupDirectory = true
                 oSmtpDotNet.QueueDirectory = "C:\temp\emailQ"
                 // Set the Random object to maintain uniqueness with files
                 // created for queuing.
                 oSmtpDotNet.RandomObject = new Random()
                 
                 ' Force the message body to be html
                 oSmtpDotNet.BodyFormat = BodyFormatTypes.HTML
                  
                 ' Send the message.  Get the return code and store it in the variable
                 ' nRC.  Then check nRC for success or failure
                 nRC = oSmtpDotNet.Send()
                 If (nRC <> ReturnCodes.SUCCESS) Then
                     ' A problem occurred.
                     ' Write out the last error encountered
                     Console.WriteLine(oSmtpDotNet.LastError)
                     ' Write out the log file contents
                     Console.WriteLine(oSmtpDotNet.LogFileToString(False))
                     Exit Function
                 End If
            
                 ' Success!
                 Console.WriteLine("Message Sent!")
            End Function
            

See Also

SmtpServer Class | SmtpServer Members | SmtpDotNet Namespace | PickupDirectory | SendToQueue | QueueDirectory | QueueDateTime | SendToPickupDirectory