Exemple #1
0
        private void SendEmail(string fullPath)
        {
            _logger.LogInformation("A new message about schedule: {time}", DateTimeOffset.Now);
            var message = new EmailService.Message(new string[] { "*****@*****.**" }, "Subject testing", fullPath);

            _emailSender.SendEmail(message);
        }
        public void AddToQueue(EmailService.Message message)
        {
            string mailInfo = JsonConvert.SerializeObject(message);

            this.messageQueue.Formatter = new BinaryMessageFormatter();

            this.messageQueue.ReceiveCompleted += this.ReceiveFromQueue;

            this.messageQueue.Send(mailInfo);

            this.messageQueue.BeginReceive();

            this.messageQueue.Close();
        }
        public void ReceiveFromQueue(object sender, ReceiveCompletedEventArgs e)
        {
            try
            {
                var msg = this.messageQueue.EndReceive(e.AsyncResult);

                EmailService.Message message = JsonConvert.DeserializeObject <EmailService.Message>(msg.Body.ToString());

                // Process the logic be sending the message

                // Restart the asynchronous receive operation.
                _emailSender.SendEmail(message);

                this.messageQueue.BeginReceive();
            }
            catch (MessageQueueException qexception)
            {
                Console.WriteLine(qexception);
            }
        }