为发件人域添加Outlook规则

时间:2018-07-17 00:28:12

标签: c# outlook dns rules

我已经创建了以下规则,用于根据发件人的地址将项目移动到所需的文件夹,但是我也想使用发件人域。

如何添加域?

    private void CreateTextAndCategoryRule(string sCompany, string sFolder, string sName)
    {
        Outlook.AddressEntry currentUser = OutlookApplication.Session.CurrentUser.AddressEntry;
        Outlook.Application OutlookApplicationL = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
        Outlook.MAPIFolder OutlookInbox = (Outlook.MAPIFolder)OutlookApplicationL.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Folders["Brokers"];
        Outlook.MAPIFolder ruleFolder = OutlookInbox.Folders[sFolder];
        Outlook.Rules rules = OutlookApplication.Session.DefaultStore.GetRules();
        Outlook.Rule textRule = rules.Create(sCompany, Outlook.OlRuleType.olRuleReceive);

        string[] iAddress = new string[1];
        iAddress[0] = sName;
        Outlook.Rule DomainRule = textRule.Conditions.SenderAddress.Address;

        DomainRule.Conditions.Account=iAddress;

        textRule.Conditions.SenderAddress.Enabled = true;


        textRule.Actions.MoveToFolder.Folder=ruleFolder;
        textRule.Actions.MoveToFolder.Enabled =true;        
        rules.Save(true); 

0 个答案:

没有答案