// public void Timeout(EmailStatusPendingTimeout state) // { // // TODO : Mailgun Events api with Message-Id as filter // var emailStatus = MailGun.CheckStatus(Data.EmailId); // var emailStatusUpdate = new EmailStatusUpdate(Data.OriginalMessage, Data.EmailId) { Status = emailStatus }; // switch (emailStatus) // { // case EmailStatus.Accepted: // RequestUtcTimeout<EmailStatusPendingTimeout>(new TimeSpan(0,0,2,0)); // break; // case EmailStatus.Delivered: // if (Data.DeliveredEmailCount == 0) // { // ReplyToOriginator(emailStatusUpdate); // Bus.SendLocal(emailStatusUpdate); // Bus.Publish(new SmsMessages.Email.Events.EmailSent // { // EmailAddress = Data.OriginalMessage.ToAddress, // BodyHtml = Data.OriginalMessage.BodyHtml, // BodyText = Data.OriginalMessage.BodyText, // Subject = Data.OriginalMessage.Subject, // Id = Data.OriginalMessage.CorrelationId, // SendTimeUtc = Data.StartTime.ToUniversalTime() // // }); // } // if (Data.DeliveredEmailCount > 10) // // TODO: Should notify originator that there is no more checking // MarkAsComplete(); // else // RequestUtcTimeout<EmailStatusPendingTimeout>(new TimeSpan(0, 2, 0, 0)); // Data.DeliveredEmailCount++; // break; // case EmailStatus.Failed: // case EmailStatus.Clicked: // case EmailStatus.Opened: // case EmailStatus.Complained: // case EmailStatus.Unsubscribed: // ReplyToOriginator(emailStatusUpdate); // Bus.SendLocal(emailStatusUpdate); // MarkAsComplete(); // break; // default: // throw new NotImplementedException(); // } // } public void Handle(SendEmail message) { using (var session = RavenDocumentStore.GetStore().OpenSession(RavenDocumentStore.ConfigurationDatabaseName())) { var emailProvider = session.Load <EmailProviderConfiguration>("EmailProviderConfiguration"); if (emailProvider == null) { Data.EmailId = MailGun.SendEmail(message); } else { switch (emailProvider.EmailProvider) { case EmailProvider.Mailgun: Data.EmailId = MailGun.SendEmail(message); break; case EmailProvider.Mandrill: Data.EmailId = MandrillWrapper.SendEmail(message); break; } } // Bus.Reply(new InternalMessages.Responses.EmailSent { EmailId = emailId, EmailSagaId = message.EmailSagaId }); } }