Introduction

If you use Microsoft’s built-in SMTP service, aspNetEmail provides the native capability to write emails directly to the Pickup directory.

Note: Because Queuing is an advanced feature of aspNetEmail, it is highly recommended to test sending email using the standard Send() methods, BEFORE using the queuing methods. This allows for easier troubleshooting.

Background

Along with IIS, Microsoft provides a SMTP service. This service can process emails files that are placed, in a proprietary format, in a directory called 'Pickup'. By default, the location for this directory can be found at C:\Inetpub\mailroot\Pickup. aspNetEmail provides the following properties and methods to write emails directly to this Pickup directory.

NOTE: In order to write emails to file system, the account using aspNetEmail must have write permissions to that directory.

[Property]
EmailMessage.MSPickupDirectory
This property allows you to manually specify the location of the Pickup directory.

[Method]
EmailMessage.SendToMSPickup()
Sends an email directly to the Pickup directory. If the directory is not specified, aspNetEmail will scan the system and attempt to locate the directory.

[Method]
EmailMessage.SendMailMergeToMSPickup()
This method is similar to SendMailMerge(), except that it will perform a mail merge, and send the resulting emails to the Pickup directory.

Both these methods have multiple overloads to accept a parameter called MSPickupDirectoryPath to manually specify the Pickup Directory.

Code Examples

Here are some simple code examples using SendToMSPickup()

[C#]

EmailMessage msg = new EmailMessage();
msg.FromAddress = "me@mycompany.com";
msg.To="you@yourcompany.com";
msg.Subject = "this email was sent to the MS Pickup directory.";
msg.Body = "this is where the body text goes.";
msg.SendToMSPickup();

 

[VB.NET]

Dim msg As New EmailMessage()
msg.FromAddress = "me@mycompany.com"
msg.To = "you@yourcompany.com"
msg.Subject = "this email was sent to the MS Pickup directory."
msg.Body = "this is where the body text goes."
msg.SendToMSPickup()

Locating the MS Pickup Directory

aspNetEmail performs a number of steps to locate the MS Pickup directory. Here is an explanation of these steps, to help you optimize your use of aspNetEmail.

  1. If an overloaded method of SendToMSPickup() is called, which accepts the parameter MSPickupDirectoryPath, aspNetEmail will write the emails to that directory.
  2. If MSPickupDirectoryPath is null, or not used, aspNetEmail will use the valued specified by the property MSPickupDirectory
  3. If the MSPickupDirectory is null or not used, aspNetEmail will scan the configuration files for an appSetting key called aspNetEmail.MSPickupDirectory. This setting can be in the application configuration file, or in the machine.config file. This allows an administrator to specify the location of the pickup directory, and hiding it’s actual location from the end user of aspNetEmail. To add this setting to the config file, add the following tags

    <appSettings>

                <add key="aspNetEmail.MSPickupDirectory" value="c:\temp\mspickup"></add>

    </appSettings>
    In this example, aspNetEmail will send all MS Pickup files to a directory called c:\temp\mspickup.

    For more information on the appSettings tag, please see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfappsettingselement.asp

  4. If the appSettings key is not used, aspNetEmail will scan the system registry to locate the appropriate keys relating to the Pickup directory location.

If none of these values can be found, or do not exist, an exception will be thrown.