none
How To Create A Template Message In Ews To Use With ServeReplyWithMessage Rule? RRS feed

  • Question

  • Hi,

    I'm trying to create a server side rule for a mailbox using EWS.
    I want the mailbox to reply automatically to incoming emails.
    To do this i have to create a template message that can be used when specifying the rule action ServerReplyWithMessage.

    I think I have two issues here:

    1: When I save the template(which is just an email message), it does not appear in the drafts folder.

    2: When I save the rule a Microsoft.Exchange.WebServices.Data.UpdateInboxRulesException exception is thrown.

    I'm using .net/c# and the EWS API Managed API. I have tried to create a rule to reply emails using a template by doing this:

                    

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
    service.Credentials = new WebCredentials(emailAddress, password);
    service.AutodiscoverUrl(emailAddress, RedirectionUrlValidationCallback);


    EmailMessage emailTemplate = new EmailMessage(service);
    emailTemplate.ItemClass = "IPM.Note.Rules.ReplyTemplate.Microsoft";
    emailTemplate.IsAssociated = true;
    emailTemplate.Subject = "Auto Response";
    emailTemplate.Body = "Hello This is a template";

    Guid MyPropertySetId = new Guid("{A11FF724-AA03-4555-9952-8FA248A11C3E}");
    var PidTagReplyTemplateId = new ExtendedPropertyDefinition(MyPropertySetId, "PidTagReplyTemplateId", MapiPropertyType.String);

    Guid testid = Guid.NewGuid();
    emailTemplate.SetExtendedProperty(PidTagReplyTemplateId, testid.ToString());

    emailTemplate.Save(); // Email should be saved to drafts folder but it isn't and no exception is thrown

    Rule newRule = new Rule();
    newRule.DisplayName = "AutoReplyRule";
    newRule.IsEnabled = true;
    newRule.Conditions.SentToOrCcMe = true;
    newRule.Actions.ServerReplyWithMessage = emailTemplate.Id;

    CreateRuleOperation createOperation = new CreateRuleOperation(newRule);
    service.UpdateInboxRules(new RuleOperation[] { createOperation }, true); // Exception of type 'Microsoft.Exchange.WebServices.Data.UpdateInboxRulesException' was thrown.


    • Edited by Billy121 Thursday, April 13, 2017 9:53 PM
    Thursday, April 13, 2017 9:51 PM