Esempio n. 1
0
        public static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost", UserName = "******", Password = "******"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "email_queue",
                                         durable: true,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    EmailQueueMessage message = new EmailQueueMessage
                    {
                        RecipientEmail = "*****@*****.**",
                        RecipientName  = "Test",
                        SenderName     = "Rocky Balboa",
                        SenderEmail    = "*****@*****.**",
                        Subject        = "Test"
                    };

                    string json = JsonConvert.SerializeObject(message);
                    var    body = Encoding.UTF8.GetBytes(json);

                    channel.BasicPublish(exchange: "",
                                         routingKey: "email_queue",
                                         basicProperties: null,
                                         body: body);
                    Console.WriteLine("Sent email: {0}", json);
                }
        }
Esempio n. 2
0
        private void CreateEmailTask(Guid jobID, string textBlobName, string recipientEmail)
        {
            var message        = new EmailQueueMessage(jobID, textBlobName, recipientEmail);
            var wrappedMessage = new CloudQueueMessage(message.ToString());

            AzureQueues.EmailQueue.AddMessage(wrappedMessage);
        }
Esempio n. 3
0
        public async Task AddToQueueAsync(EmailQueueMessage messageModel)
        {
            var storageAccount = CloudStorageAccount.Parse(_configProvider.GetConnectionString(Application.BandCamsStorage));
            var cloudQueue     = storageAccount.CreateCloudQueueClient().GetQueueReference(_configProvider.GetQueueName(Queue.EmailQueue));

            var message = new CloudQueueMessage(JsonConvert.SerializeObject(messageModel));
            await cloudQueue.AddMessageAsync(message);
        }
Esempio n. 4
0
        private void ProcessEmailQueueMessage(CloudQueueMessage queueMessage)
        {
            string messageContent = queueMessage.AsString;

            Trace.TraceInformation("Processing email queue message: " + messageContent);

            EmailQueueMessage emailMessage = null;
            Exception         exception    = null;

            try
            {
                emailMessage = EmailQueueMessage.Parse(messageContent);
                SendOCRTextByEmail(emailMessage.TextBlobName, emailMessage.RecipientEmail);
                DeleteTextBlob(emailMessage.TextBlobName);
            }
            catch (Exception ex)
            {
                Trace.TraceError("An error occurred while processing email queue message. Details: " + ex);
                exception = ex;

                if (emailMessage == null)
                {
                    Trace.TraceError("Invalid message format. Deleting.");
                    AzureQueues.EmailQueue.DeleteMessage(queueMessage);
                    return;
                }
            }

            try
            {
                var job = AzureTables.OCRJobRepository.GetOCRJob(emailMessage.JobID, emailMessage.RecipientEmail);
                if (exception == null)
                {
                    job.IsCompleted  = true;
                    job.ErrorMessage = null;
                    AzureTables.OCRJobRepository.UpdateOCRJob(job);

                    Trace.TraceInformation("Message (JobID = {0}) successfully processed, deleting.", emailMessage.JobID);
                    AzureQueues.EmailQueue.DeleteMessage(queueMessage);
                }
                else
                {
                    job.IsCompleted  = true;
                    job.ErrorMessage = exception.ToString();
                    AzureTables.OCRJobRepository.UpdateOCRJob(job);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Failed to update job status: " + ex);
            }
        }
Esempio n. 5
0
        private static SendGridMessage CreateEmail(EmailQueueMessage emailQueueMessage)
        {
            var msg = new SendGridMessage
            {
                From             = new EmailAddress(emailQueueMessage.SenderEmail, emailQueueMessage.SenderEmailAlias),
                Subject          = emailQueueMessage.Subject,
                PlainTextContent = emailQueueMessage.Body,
                HtmlContent      = emailQueueMessage.Body,
            };

            msg.AddTo(new EmailAddress(emailQueueMessage.EmailTo));

            return(msg);
        }
Esempio n. 6
0
        public void Send(EmailQueueMessage message)
        {
            var mimeMessage = new MimeMessage();
            mimeMessage.From.Add(new MailboxAddress(message.SenderName, message.SenderEmail));
            mimeMessage.To.Add(new MailboxAddress(message.RecipientName, message.RecipientEmail));
            mimeMessage.Subject = message.Subject;
            mimeMessage.Body = new TextPart("plain")
            {
                Text = message.Body
            };

            using (var client = new SmtpClient())
            {
                client.Connect(this.smtpServer, this.port, false);
                client.Authenticate(this.user, this.password);
                client.Send(mimeMessage);
                client.Disconnect(true);
            }
        }
Esempio n. 7
0
         public static void SendMessage(MailMessage message)
        {
            var smtpClientType = CommonFunctions.GetSetting(Constant.SmtpType);
             

           switch (smtpClientType)
            {
                case Constant.Internal:

                    SmtpClient smtpClient = new SmtpClient();
                    MailMessage mailMessage = (MailMessage) message;
                    smtpClient.Send(mailMessage);
                    break;

                case Constant.SendGrid:

                    EmailQueueMessage sendGridMessage = new EmailQueueMessage(message);
                    Task.Run(() => SendGridAsync(sendGridMessage));
                    break;
                default:
                    throw new NotImplementedException();
            }

        }
Esempio n. 8
0
        public static void SendMessage(MailMessage message)
        {
            var smtpClientType = CommonFunctions.GetSetting(Constant.SmtpType);


            switch (smtpClientType)
            {
            case Constant.Internal:

                SmtpClient  smtpClient  = new SmtpClient();
                MailMessage mailMessage = (MailMessage)message;
                smtpClient.Send(mailMessage);
                break;

            case Constant.SendGrid:

                EmailQueueMessage sendGridMessage = new EmailQueueMessage(message);
                Task.Run(() => SendGridAsync(sendGridMessage));
                break;

            default:
                throw new NotImplementedException();
            }
        }
Esempio n. 9
0
 private static void ReplaceTemplateVariables(string link, EmailQueueMessage template)
 {
     template.Body = template.Body.Replace("#{CreateDate}#", DateTime.Now.ToString(CultureInfo.CurrentCulture));
     template.Body = template.Body.Replace("#{Link}#", link);
 }