Search code examples
c#emailsmtpclient

Drop email send into different folder


I have a mail box where all support emails come through to the default location "Inbox", we recently added in some new programs with automatically run every day. We've set them so when they run, it will send an email to this mail box.

What I want to do is separate out the user requests from the automation emails

I have this block of code which will send out an email and I've been trying to route it to the Automation folder

var email = new MailMessage(from, to, subject, emailBody)
{
    IsBodyHtml = true
};

var client = new SmtpClient("", 0)
{
    DeliveryFormat = SmtpDeliveryFormat.International,
    DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
    PickupDirectoryLocation = @"\\Automation\",
    UseDefaultCredentials = false,
    Credentials = new System.Net.NetworkCredential("", "")
};

client.Send(email);

Text

I keep getting the error that the network path does not exist?


Solution

  • PickupDirectoryLocation is for local pickup. Its intention is not to set destination folder. And you cannot do it with SMTP in anyway.

    SmtpClient.PickupDirectoryLocation Property
    Gets or sets the folder where applications save mail messages to be processed by the local SMTP server.

    Reference