Esempio n. 1
0
        public async Task SendVideo(FileInfo video, Recipient recipient, string body)
        {
            using (var client = new SmtpClient(server.Address, server.Port))
            {
                client.EnableSsl = server.UseSsl;
                client.UseDefaultCredentials = false;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Credentials = new NetworkCredential(server.Username, server.Password);
                client.SendCompleted += OnSendCompleted;

                using (var attachment = new Attachment(video.FullName, recipient.ContentType))
                {
                    attachment.Name = recipient.AttachmentName;
                    using (var message = new MailMessage(server.From, recipient.Address))
                    {
                        message.Subject = server.Subject ?? string.Empty;
                        message.Body = body ?? string.Empty;
                        message.Attachments.Add(attachment);
                        await this.SendInternalAsync(client, message);
                    }
                }
            }
        }
Esempio n. 2
0
        private async void SendVideoToRecipient(string input, Recipient recipient)
        {
            FileInfo video;

            try
            {
                // Acquiring a lock to ensure that the process generating the video is done with the file.
                using (await LockFileAsync(input))
                {
                }

                // Release the lock before running the encoder otherwise it won't be able to open the file.
                video = await encoder.Encode(input);
            }
            catch (Exception e)
            {
                Log.Warning($"Failed to process file: {input} with {e.GetType().Name}: {e.Message}");
                return;
            }

            try
            {
                await this.sender.SendVideo(video, recipient, this.folder.Message);
            }
            catch (Exception e)
            {
                Log.Warning($"Failed to send video to {recipient.Name} with {e.GetType().Name}: {e.Message}");
                return;
            }
            finally
            {
                video.Delete();
            }

            Log.Info($"Video successfully sent to {recipient.Name} ({recipient.Address})");
        }