Пример #1
0
        public async Task <MailAccount> GetMailAccount(int accountId, bool includeUser = false)
        {
            if (accountId <= 0)
            {
                _logger.Warn($"MailAccountService.GetMailAccount() no mail account found with id:{accountId}");
                throw new ArgumentException($"MailAccountService.GetMailAccount() no mail account found with id:{accountId}");
            }

            // get the mail account
            var mailAccount = await _repo.GetMailAccount(accountId, includeUser);

            // log if we don't have the requested mail account
            if (mailAccount == null)
            {
                _logger.Debug($"MailAccountService.GetMailAccount() no mail account found with id:{accountId}");
                return(null);
            }

            // decrypt the mail accounts password
            mailAccount.SmtpPassword = _encryptionService.DecryptText(mailAccount.SmtpPassword);

            // if we have an user account, we need to decrypt its password too
            if (mailAccount.User != null)
            {
                mailAccount.User.Password = _encryptionService.DecryptText(mailAccount.User.Password);
            }

            return(mailAccount);
        }
Пример #2
0
        private void ConfigureClientToRedirectMailsToDisk(SmtpClient client)
        {
            // http://stackoverflow.com/questions/567765/how-can-i-save-an-email-instead-of-sending-when-using-smtpclient
            client.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
            client.PickupDirectoryLocation = GetMailDiskFolderPath();

            // if we are working with a relative path we need to modify it
            if (client.PickupDirectoryLocation.StartsWith("~"))
            {
                var root       = AppDomain.CurrentDomain.BaseDirectory;
                var pickupRoot = client.PickupDirectoryLocation
                                 .Replace("~", root);

                pickupRoot = pickupRoot.Replace("/", @"\");
                client.PickupDirectoryLocation = pickupRoot;
            }

            // ensure that the pickup location exists
            if (_directory.Exists(client.PickupDirectoryLocation))
            {
                return;
            }

            _logger.Info($"RnMailClient - mail pickup directory not found ({client.PickupDirectoryLocation})," +
                         " attempting to create it now");

            _directory.CreateDirectory(client.PickupDirectoryLocation);

            _logger.Debug("RnMailClient - successfully created mail pickup directory");
        }
Пример #3
0
        public async Task <MailUser> GetUserAccount(int userId)
        {
            if (userId <= 0)
            {
                _logger.Warn($"UserAccountService.GetUserAccount() invalid userId provided ({userId})");
                throw new ArgumentException($"Invalid userId provided: {userId}");
            }

            // fetch the user from the repository
            var userAccount = await _repo.GetUserAccount(userId);

            // ensure that we have a user to work with
            if (userAccount == null)
            {
                _logger.Debug($"UserAccountService.GetUserAccount() no user account found for userId ({userId})");
                return(null);
            }

            // we now need to decode the users password
            userAccount.Password = _encryption.DecryptText(userAccount.Password);

            return(userAccount);
        }