Writing email to the IIS Server's SMTP service pickup directory is
another new feature of System.Net.Mail. The SMTP pickup directory is a special
directory used by Microsoft's SMTP service to send email. Any email files found
in that directory are processed and delivered over SMTP. If the delivery
process fails, the files are stored in a queue directory for delivery at
another time. If a fatal error occurs (such as a DNS resolution error), the
files are moved to the Badmail directory.
By writing to the pickup directory, this speeds up the process
because the entire chatting SMTP layer used for relaying is by passed. Below is
an example of how to write directly to the Pickup directory.
[ C# ]
public static void PickupDirectory()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";
//if we are using the IIS SMTP Service, we can write the message
//directly to the PickupDirectory, and bypass the Network layer
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtp.Send(mail);
}
[ VB.NET ]
Public Sub PickupDirectory()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is the body content of the email."
'if we are using the IIS SMTP Service, we can write the message
'directly to the PickupDirectory, and bypass the Network layer
Dim smtp As New SmtpClient()
smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
smtp.Send(mail)
End Sub 'PickupDirectory