1
votes

I am trying to read out the mailroot-path for the Drop and Pickup folders for my SMTP Virtual Server Domain. I currently need this for domains created with IIS 6.0 but in the long run will also need my Application to be compatable with IIS 7. Can anybody give me some pointers on how to do this?

Thanks!

Further details:

  • What I have: SMTP Virtual Server Domain with a local alias: mydomain

  • What I want: The mailroot path (default: C:\inetpub\mailroot) where the Badmail, Drop, Pickup and Queue folders are to be found. If that is not possible, then at least the path to the Drop folder

  • Why do I want this? E.g. using IIS 6.0, users can change the Drop directory to a user specific location. I therefore do not want to hardcode the path, but read it out using c#.

  • I have tried to find this information by:

    • Reading out virtual directories

    • Checking the iisWebSite Properties

    • SmtpDeliveryMethod.PickupDirecotryFomIis

    • System.Net.Mail.IisPickupDirectory.GetPickupDirectory() --> cannot find Method

    • Reading the smtp.PickupDirecotryLocation into a string --> returns an empty string

Would really appriciate any help/ideas!

2

2 Answers

0
votes

I am not sure but this might help you. As both IIS6 and IIS7 have same kind of setup.

http://www.kbcafe.com/articles/HowTo.SMTP.CSharp.pdf

0
votes

The information you are looking for is in IIS metabase. There are managed classes to access the metabase, but you can also just read file directly. Here's a sample code:

    public static string GetSmtpPickupFolder()
    {
        var doc = new XmlDocument();
        var fileName = Path.Combine(Environment.GetFolderPath(
                 Environment.SpecialFolder.Windows), @"System32\inetsrv\MetaBase.xml");
        if (!File.Exists(fileName))
        {
            return null;
        }

        doc.Load(fileName);

        var nsMgr = new XmlNamespaceManager(doc.NameTable);
        nsMgr.AddNamespace("c", doc.DocumentElement.NamespaceURI);

        var node = doc.SelectSingleNode(
            "/c:configuration/c:MBProperty/c:IIsSmtpServer", nsMgr);
        if (node == null)
        {
            return null;
        }

        var attr = node.Attributes["PickupDirectory"];
        if (attr == null)
        {
            return null;
        }

        return attr.Value;
    }

Make sure that you run it as 64 bit application, otherwise file system redirection will send you to c:\windows\SysWOW64 instead