private static async Task SendAllFles(DehsSettings settings1, AssetHelper assetHelper,
                                       JoinRpgClient joinRpgClient, DehsSettings settings)
 {
     using (var mailClient = new MailClient(settings1))
     {
         mailClient.Connect();
         await assetHelper.SendAllFiles(
             (file, characterId) => SendFileToCharacter(joinRpgClient, characterId, file, settings,
                                                        mailClient));
     }
 }
        private static async Task <bool> SendFileToCharacter(JoinRpgClient joinRpgClient,
                                                             int characterId, FileSystemInfo file, DehsSettings settings, MailClient mailClient)
        {
            Log.Info($"[{characterId}] File {file.Name}");
            var character = await joinRpgClient.GetCharacter(characterId);

            var email = character.Fields
                        .SingleOrDefault(field => field.ProjectFieldId == settings.EmailFieldId)?.Value;

            Log.Info($"[{characterId}] Email {email} ready, applying delay");

            await Task.Delay(20 * 1000);

            if (string.IsNullOrWhiteSpace(email))
            {
                return(false);
            }

            try
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress(settings.FromName, settings.FromEmail));
                message.To.Add(new MailboxAddress(email, email + "@" + settings.EmailServer));
                message.Subject = "Хакерский аккаунт и стартовый набор кодов";

                message.Body = new TextPart("plain")
                {
                    Text = File.ReadAllText(file.FullName)
                };

                await mailClient.SendAsync(message);
            }
            catch (Exception exception)
            {
                Log.Warn($"Failed to send to address {email}. Reason {exception}");
                return(false);
            }
            Log.Info("Send success");
            return(true);
        }