【问题标题】:Readout mailroot-path for IIS 6 & 7 using c#使用 c# 读取 IIS 6 和 7 的 mailroot-path
【发布时间】:2013-06-07 00:14:07
【问题描述】:

我正在尝试为我的 SMTP 虚拟服务器域读取 Drop 和 Pickup 文件夹的 mailroot-path。我目前需要为使用 IIS 6.0 创建的域提供此功能,但从长远来看,我的应用程序还需要与 IIS 7 兼容。谁能给我一些有关如何执行此操作的指示?

谢谢!

更多详情:

  • 我有什么: 具有本地别名的 SMTP 虚拟服务器域:mydomain

  • 我想要什么: 可以找到死信、投递、分拣和队列文件夹的邮件根路径(默认值:C:\inetpub\mailroot)。如果这不可能,那么至少是 Drop 文件夹的路径

  • 我为什么要这个? 例如。使用 IIS 6.0,用户可以将投递目录更改为用户特定的位置。因此,我不想对路径进行硬编码,而是使用 c# 将其读出。

  • 我已尝试通过以下方式查找此信息:

    • 读出虚拟目录

    • 检查 iisWebSite 属性

    • SmtpDeliveryMethod.PickupDirecotryFomIis

    • System.Net.Mail.IisPickupDirectory.GetPickupDirectory() --> 找不到方法

    • 将 smtp.PickupDirecotryLocation 读入字符串 --> 返回一个空字符串

真的会感谢任何帮助/想法!

【问题讨论】:

    标签: c# iis iis-7 iis-6 filepath


    【解决方案1】:

    我不确定,但这可能会对您有所帮助。因为 IIS6 和 IIS7 都有相同的设置。

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

    【讨论】:

    • 谢谢!我通读了这篇文章。这很有趣,虽然不是我真正想要的。我可能没有足够清楚地说明我的问题。我将编辑我的问题...
    【解决方案2】:

    您要查找的信息位于 IIS 元数据库中。有访问元数据库的托管类,但您也可以直接读取文件。这是一个示例代码:

        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;
        }
    

    确保将其作为 64 位应用程序运行,否则文件系统重定向会将您发送到 c:\windows\SysWOW64

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      • 2014-06-25
      • 2011-02-26
      • 2012-01-05
      相关资源
      最近更新 更多