Smtp.NET 3 Documentation

SmtpServer.SendToPickupDirectory Property

Specifies whether to create a "eml" file that is recognized by IIS/Exchange Smtp Server.

[Visual Basic]
Public Property SendToPickupDirectory As Boolean
[C#]
public bool SendToPickupDirectory {get; set;}

Property Value

True or False. The default value is False.

Remarks

This property requires the QueueDirectory property to be set. Setting this property to true, will create an "eml" file that is placed in the directory specified with the PickupDirectory property.

If the property SendToQueue is also set to true, messages will be first sent to the queue directory, as specified by the QueueDirectory property, then routed to the IIS/Exchange Pickup Directory as specified by the PickupDirectory property. This is useful for scheduling delivery of message through IIS/Exchange.

** Caveat to queuing logic: If the following conditions are met, then the message will be dropped in the PickupDirectory and NOT go through the queue: 1. SendToQueue is true 2. SendToPickupDirectory is true 3. QueueDateTime is not set or the date/time is in the past 4. PickupDirectory is set either explicitly, by setting the property or the IUSR_MACHINENAME user has access to the registry and an entry for PickupDirectory exists.

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 Pickup Directory
                 oSmtpDotNet.SendToPickupDirectory = true;
                 oSmtpDotNet.PickupDirectory = "C:\\Inetpub\\mailroot\\Pickup";
                 
                 // 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 Pickup Directory
                 oSmtpDotNet.SendToPickupDirectory = true
                 oSmtpDotNet.PickupDirectory = "C:\Inetpub\mailroot\Pickup"
                 
                 ' 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 | RandomObject