Exemple #1
0
        /// <summary>
        /// Creates a disabled Inbox rule that searches for a string in the subject, and if the condition is met,
        /// moves the email message to the Junk Email folder and adds a category to the mail. This Inbox rule
        /// is not visible from Outlook 2013.
        /// </summary>
        /// <param name="service">An ExchangeService object with credentials and the EWS URL.</param>
        static void CreateInboxRule(ExchangeService service)
        {
            // Create an Inbox rule.
            Rule newRule = new Rule();

            newRule.DisplayName = "MoveInterestingToJunk";
            newRule.Priority    = 1;
            newRule.IsEnabled   = false;

            // Specify the conditions that must be met to trigger the rule. There are many condition
            // options for specifying an Inbox rule.
            newRule.Conditions.ContainsSubjectStrings.Add("Interesting");

            // Specify the actions that will be taken on items that meet the conditions. There are
            // many action options for specifying an Inbox rule.
            newRule.Actions.MoveToFolder = WellKnownFolderName.JunkEmail;
            newRule.Actions.AssignCategories.Add("Junk category");

            // Specify the exceptions that exclude the rule from running on an email message. There are
            // many exceptions that can be specified on an Inbox rule.
            newRule.Exceptions.IsMeetingRequest = true;

            // Create the CreateRuleOperation object.
            CreateRuleOperation createOperation = new CreateRuleOperation(newRule);

            // Update the collection of Inbox rules with the new rule. This results in an UpdateInboxRules operation
            // call to EWS.
            service.UpdateInboxRules(new RuleOperation[] { createOperation }, true);
        }
Exemple #2
0
        //gavdcodeend 19

        //gavdcodebegin 20
        static void CreateInboxRule(ExchangeService ExService)
        {
            Rule newRule = new Rule
            {
                DisplayName = "MoveEmailToJunk",
                Priority    = 1,
                IsEnabled   = true
            };

            newRule.Conditions.ContainsSubjectStrings.Add("ItIsJunk");
            newRule.Actions.MoveToFolder = WellKnownFolderName.JunkEmail;

            CreateRuleOperation myOperation = new CreateRuleOperation(newRule);

            ExService.UpdateInboxRules(new RuleOperation[] { myOperation }, true);
        }
Exemple #3
0
        public static void AddNewRule(ExchangeService service, string name, List <string> subjects, List <string> bodies, string forward)
        {
            Console.WriteLine(" [>] Constructing rule");

            Rule newRule = new Rule();

            // set name

            Console.WriteLine(" [>] Name: {0}", name);
            newRule.DisplayName = name;

            // set subjects
            if (subjects.Any())
            {
                foreach (string subject in subjects)
                {
                    Console.WriteLine(" [>] Subject: {0}", subject);
                    newRule.Conditions.ContainsSubjectStrings.Add(subject);
                }
            }

            // set body
            if (bodies.Any())
            {
                foreach (string body in bodies)
                {
                    Console.WriteLine(" [>] Body: {0}", body);
                    newRule.Conditions.ContainsBodyStrings.Add(body);
                }
            }

            // forwartd to
            Console.WriteLine(" [>] Forward to: {0}", forward);
            newRule.Actions.ForwardAsAttachmentToRecipients.Add(forward);

            Console.WriteLine(" [>] Adding rule");

            CreateRuleOperation createRule = new CreateRuleOperation(newRule);

            service.UpdateInboxRules(new RuleOperation[] { createRule }, true);

            Console.WriteLine(" [>] Done");
        }
Exemple #4
0
        public void AddToInbox()
        {
            var rule = new CreateRuleOperation(Rule);

            Service.UpdateInboxRules(new RuleOperation[] { rule }, true);
        }