public IMailboxManager CreateMailboxManager(Config.EmailSettings emailSettings) { var credentials = new EWSConnectionManger.Credentials { EmailAddress = emailSettings.EWSMailboxAddress, UserName = emailSettings.EWSUsername, Password = DPAPIHelper.ReadDataFromFile(emailSettings.EWSPasswordFile) }; var exchangeService = _connectionManger.GetConnection(credentials); var postProcessor = GetPostProcesor(emailSettings, exchangeService.Service); switch (emailSettings.ServiceType) { case Config.EmailSettings.MailboxServiceType.EWSByFolder: return(new FolderMailboxManager( exchangeService.Service, emailSettings.IncomingFolder, postProcessor)); case Config.EmailSettings.MailboxServiceType.EWSByRecipients: return(new RecipientsMailboxManager( exchangeService.Router, ParseDelimitedList(emailSettings.Recipients, ';'), postProcessor)); default: throw new BadConfigException( "EmailSettings.ServiceType", string.Format("Invalid mailbox service type defined in config ({0})", emailSettings.ServiceType)); } }
private static IMessagePostProcessor GetPostProcesor(Config.EmailSettings emailSettings, ExchangeService service) { if (string.IsNullOrEmpty(emailSettings.CompletedFolder) || string.IsNullOrEmpty(emailSettings.ErrorFolder)) { return(new DeleterMessagePostProcessor()); } return(new ArchiverMessagePostProcessor(emailSettings.CompletedFolder, emailSettings.ErrorFolder, service)); }
public IMailboxManager CreateMailboxManager(Config.EmailSettings emailSettings) { var credentialsHelper = new Helpers.CredentialsHelper(); string password = credentialsHelper.GetPassword(emailSettings.EWSPasswordFile, emailSettings.EncryptionScope, emailSettings.EWSKeyVaultSecret); var credentials = new EWSConnectionManger.Credentials { EmailAddress = emailSettings.EWSMailboxAddress, UserName = emailSettings.EWSUsername, Password = password }; var exchangeService = _connectionManger.GetConnection(credentials, emailSettings.UseConversationGuidOnly); var postProcessor = GetPostProcesor(emailSettings, exchangeService.Service); switch (emailSettings.ServiceType) { case Config.EmailSettings.MailboxServiceType.EWSByFolder: if (emailSettings.Recipients != null) { return(new FolderMailboxManager( exchangeService.Service, emailSettings.IncomingFolder, postProcessor, emailSettings.UseConversationGuidOnly, ParseDelimitedList(emailSettings.Recipients, ';'))); } else { return(new FolderMailboxManager( exchangeService.Service, emailSettings.IncomingFolder, postProcessor, emailSettings.UseConversationGuidOnly)); } case Config.EmailSettings.MailboxServiceType.EWSByRecipients: return(new RecipientsMailboxManager( exchangeService.Router, ParseDelimitedList(emailSettings.Recipients, ';'), postProcessor)); default: throw new BadConfigException( "EmailSettings.ServiceType", string.Format("Invalid mailbox service type defined in config ({0})", emailSettings.ServiceType)); } }