public void CanSendTemplateEmail() { using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var fixture = new FixtureData(uow); var outboundEmailDaemon = new OutboundEmail(); // SETUP var email = fixture.TestEmail1(); // EXECUTE //var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "template", null); var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "a16da250-a48b-42ad-88e1-bdde24ae1dee", null); uow.SaveChanges(); //adding user for alerts at outboundemail.cs //If we don't add user, AlertManager at outboundemail generates error and test fails. AddNewTestCustomer(email.From); var mockEmailer = new Mock<IEmailPackager>(); mockEmailer.Setup(a => a.Send(envelope)).Verifiable(); ObjectFactory.Configure( a => a.For<IEmailPackager>().Use(mockEmailer.Object).Named(EnvelopeDO.SendGridHander)); DaemonTests.RunDaemonOnce(outboundEmailDaemon); // VERIFY mockEmailer.Verify(a => a.Send(envelope), "OutboundEmail daemon didn't dispatch email via Mandrill."); } }
public async Task <IActionResult> PushEmail([FromBody] NotificationMessage emailSubscribers) { try { if (!ModelState.IsValid) { LogInfo.Error(StatusMessages.DomainValidationError); new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, Message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)) }; } OutboundEmail _email = new OutboundEmail(); ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse forgotPasswordMsgTemplate = await _configAccess.GetEmailNotificationTemplate(NotificationEvent.ForgetPassword.ToString()); EmailTemplate template = (EmailTemplate)forgotPasswordMsgTemplate.Results; var responses = await _email.SendEmail(emailSubscribers, _iconfiguration, template); foreach (Mandrill.Model.MandrillSendMessageResponse response in responses) { //DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLog(new NotificationLog { Status=response.Status.ToString(), Email=response.Email }); } // log notificaiton in db return(Ok(new ServerResponse { HasSucceeded = true, Message = StatusMessages.SuccessMessage })); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, IsDomainValidationErrors = false })); } }
internal static EmailModel GetModelFromOutboundEmail(OutboundEmail mail, bool displayResend, string errormessage = null) { return(new EmailModel { OutboundEmailId = mail.OutboundEmailId, CreatedAt = mail.CreatedAt, Subject = mail.Subject, Body = mail.PlainBody, Recipient = mail.Recipient, SentAt = mail.DeliveredAt, ReplacingEmailId = mail.ReplacedByEmail?.OutboundEmailId, ResentAt = mail.ReplacedByEmail?.CreatedAt, ErrorMessage = errormessage, DisplayResend = displayResend }); }
public void FailsToSendInvalidEnvelope() { using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var fixture = new FixtureData(uow); var outboundEmailDaemon = new OutboundEmail(); // SETUP var email = fixture.TestEmail1(); // EXECUTE var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "a16da250-a48b-42ad-88e1-bdde24ae1dee", null); envelope.Handler = "INVALID EMAIL PACKAGER"; uow.SaveChanges(); //adding user for alerts at outboundemail.cs //If we don't add user, AlertManager at outboundemail generates error and test fails. AddNewTestCustomer(email.From); var mockMandrillEmailer = new Mock<IEmailPackager>(); mockMandrillEmailer.Setup(a => a.Send(envelope)).Throws<ApplicationException>(); // shouldn't be invoked ObjectFactory.Configure( a => a.For<IEmailPackager>().Use(mockMandrillEmailer.Object).Named(EnvelopeDO.SendGridHander)); var mockSendGridEmailer = new Mock<IEmailPackager>(); mockSendGridEmailer.Setup(a => a.Send(envelope)).Throws<ApplicationException>(); // shouldn't be invoked ObjectFactory.Configure( a => a.For<IEmailPackager>().Use(mockSendGridEmailer.Object).Named(EnvelopeDO.SendGridHander)); // VERIFY Assert.Throws<UnknownEmailPackagerException>( () => DaemonTests.RunDaemonOnce(outboundEmailDaemon), "OutboundEmail daemon didn't throw an exception for invalid EnvelopeDO."); } }
private void AddNewTestCustomer(EmailAddressDO emailAddress) { using (var uow = ObjectFactory.GetInstance<IUnitOfWork>()) { var fixture = new FixtureData(uow); var outboundEmailDaemon = new OutboundEmail(); emailAddress.Recipients = new List<RecipientDO>() { new RecipientDO() { EmailAddress = Email.GenerateEmailAddress(uow, new MailAddress("*****@*****.**")), EmailParticipantType = EmailParticipantType.To } }; uow.AspNetRolesRepository.Add(fixture.TestRole()); var u = new UserDO(); var user = new User(); UserDO currUserDO = new UserDO(); currUserDO.EmailAddress = emailAddress; uow.UserRepository.Add(currUserDO); } }
public async void ProcessNotification(object message) { try { Amazon.SQS.Model.Message msg = (Amazon.SQS.Model.Message)message; string queMessage = msg.Body; //LogInfo.Information("8 - bsubscription is {" + msg.MessageId + "} object"); SNSSubscription subscription = JsonConvert.DeserializeObject <SNSSubscription>(queMessage); //LogInfo.Information("8 - bsubscription is {" + subscription.MessageId + "} object"); NotificationMessage NotMessage = JsonConvert.DeserializeObject <NotificationMessage>(subscription.Message); //LogInfo.Information("9 - NotMessage is {" + NotMessage.Message +" "+ NotMessage.MessageType + "} object"); // SNSSubscription messageObject= new SNSSubscription { Message=me}; // NotificationMessage notification= JsonConvert.DeserializeObject<NotificationMessage>(messageObject.Message); if (NotMessage.MessageType == NotificationMsgType.Email.GetDescription()) { OutboundEmail _email = new OutboundEmail(); ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse emailTemplate = await _configAccess.GetEmailNotificationTemplate(NotMessage.Message.messagetemplate.ToString()); EmailTemplate template = (EmailTemplate)emailTemplate.Results; var responses = await _email.SendEmail(NotMessage, _iconfiguration, template); foreach (Mandrill.Model.MandrillSendMessageResponse response in responses) { foreach (NotificationParams param in NotMessage.Message.parameters) { if (response.Email == param.emailaddress) { DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLog(new NotificationLog { Status = response.Status.ToString() == "Sent" ? 1 : 0, Email = response.Email, EmailTemplateID = template.EmailTemplateID, EmailBody = template.EmailBody, EmailSubject = template.EmailSubject, ScheduledOn = subscription.Timestamp, SendOn = DateTime.Now }); } } } } else if (NotMessage.MessageType == NotificationMsgType.SMS.GetDescription()) { OutboundSMS _SMS = new OutboundSMS(); TextMessage smsData = new TextMessage(); ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse smsTemplate = await _configAccess.GetSMSNotificationTemplate(NotMessage.Message.messagetemplate.ToString()); SMSTemplates template = (SMSTemplates)smsTemplate.Results; foreach (var item in NotMessage.Message.parameters) { smsData.PhoneNumber = item.mobilenumber; smsData.SMSText = template.SMSTemplate.Replace("*|NAME|*", item.name) .Replace("*|PARAM1|*", item.param1) .Replace("*|PARAM2|*", item.param2) .Replace("*|PARAM3|*", item.param3) .Replace("*|PARAM4|*", item.param4) .Replace("*|PARAM5|*", item.param5) .Replace("*|PARAM6|*", item.param6) .Replace("*|PARAM7|*", item.param7) .Replace("*|PARAM8|*", item.param8) .Replace("*|PARAM9|*", item.param9) .Replace("*|PARAM10|*", item.param10); //LogInfo.Information("10 - SendSMS is { "+ smsData+ "}"); string response = await _SMS.SendSMSNotification(smsData, _iconfiguration); await _configAccess.CreateSMSNotificationLog(new SMSNotificationLog() { Email = NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault(), Mobile = smsData.PhoneNumber, SMSTemplateID = template.SMSTemplateID, SMSText = smsData.SMSText, Status = response != "failure" ? 1 : 0, ScheduledOn = subscription.Timestamp, SendOn = DateTime.Now }); } //LogInfo.Information("10 - SendSMSLog is { " + NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault() + " " + smsData.PhoneNumber + " "+ response + "}"); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); } }