public EmailDO TestEmail1()
        {

            EmailDO curEmailDO = new EmailDO();
            curEmailDO.Id = 1;
            curEmailDO.From = TestEmailAddress1();
            curEmailDO.AddEmailRecipient(EmailParticipantType.To, TestEmailAddress2());
            curEmailDO.Subject = "Main Subject";
            curEmailDO.HTMLText = "This is the Body Text";
            return curEmailDO;

        }
        public EmailDO TestEmail3()
        {

            EmailDO curEmailDO = new EmailDO();
            curEmailDO.Id = 3;
            curEmailDO.From = TestEmailAddress3();
            curEmailDO.AddEmailRecipient(EmailParticipantType.To, TestEmailAddress3());
            curEmailDO.Subject = "Main Subject";
            curEmailDO.HTMLText = "This Email is intended to be used with KwasantIntegration account ";
            return curEmailDO;

        }
Exemple #3
0
        public async Task SendAsync(IdentityMessage message)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                String senderMailAddress = ObjectFactory.GetInstance<IConfigRepository>().Get("EmailFromAddress_DirectMode");

                EmailDO emailDO = new EmailDO();
                emailDO.AddEmailRecipient(EmailParticipantType.To, Email.GenerateEmailAddress(uow, new MailAddress(message.Destination)));
                emailDO.From = Email.GenerateEmailAddress(uow, new MailAddress(senderMailAddress));

                emailDO.Subject = message.Subject;
                emailDO.HTMLText = message.Body;

                uow.EnvelopeRepository.ConfigurePlainEmail(emailDO);
                uow.SaveChanges();
            }
        }
Exemple #4
0
        public async Task ForgotPasswordAsync(string userEmail)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var userManager = new KwasantUserManager(uow);
                var user = await userManager.FindByEmailAsync(userEmail);
                if (user == null/* || !(await userManager.IsEmailConfirmedAsync(user.Id))*/)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return;
                }

                var code = await userManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = string.Format("{0}Account/ResetPassword?UserId={1}&code={2}", Server.ServerUrl, user.Id, code);

                var emailDO = new EmailDO();
                IConfigRepository configRepository = ObjectFactory.GetInstance<IConfigRepository>();
                string fromAddress = configRepository.Get("EmailAddress_GeneralInfo");
                var emailAddressDO = uow.EmailAddressRepository.GetOrCreateEmailAddress(fromAddress);
                emailDO.From = emailAddressDO;
                emailDO.FromID = emailAddressDO.Id;
                emailDO.AddEmailRecipient(EmailParticipantType.To, uow.EmailAddressRepository.GetOrCreateEmailAddress(userEmail));
                emailDO.Subject = "Password Recovery Request";

                uow.EnvelopeRepository.ConfigureTemplatedEmail(emailDO, configRepository.Get("ForgotPassword_template"),
                                                               new Dictionary<string, object>()
                                                                   {{"-callback_url-", callbackUrl}});
                uow.SaveChanges();
            }
        }
        public void GenerateWelcomeEmail(string curUserId)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var curUser = uow.UserRepository.GetByKey(curUserId);
                EmailDO curEmail = new EmailDO();
                curEmail.From = uow.EmailAddressRepository.GetOrCreateEmailAddress(_configRepository.Get("EmailFromAddress_DirectMode"), _configRepository.Get("EmailFromName_DirectMode"));
                curEmail.AddEmailRecipient(EmailParticipantType.To, curUser.EmailAddress);
                curEmail.Subject = "Welcome to Kwasant";

                uow.EnvelopeRepository.ConfigureTemplatedEmail(curEmail, _configRepository.Get("welcome_to_kwasant_template"), null); //welcome to kwasant v2 template
                uow.SaveChanges();
            }
        }
        private void SendBREmails(String toAddress, IEnumerable<BookingRequestDO> bookingRequests, IUnitOfWork uow)
        {
            EmailRepository emailRepo = uow.EmailRepository;
            const string message = "A new booking request has been created. From '{0}'.";
            foreach (BookingRequestDO bookingRequest in bookingRequests)
            {
                EmailDO outboundEmail = new EmailDO
                {
                    Subject = "New booking request!",
                    HTMLText = String.Format(message, bookingRequest.From.Address),
                    EmailStatus = EmailState.Queued
                };

                var toEmailAddress = uow.EmailAddressRepository.GetOrCreateEmailAddress(toAddress);
                outboundEmail.AddEmailRecipient(EmailParticipantType.To, toEmailAddress);
                outboundEmail.From = _emailAddress.GetFromEmailAddress(uow, toEmailAddress, bookingRequest.Customer);

                uow.EnvelopeRepository.ConfigurePlainEmail(outboundEmail);
                emailRepo.Add(outboundEmail);
            }
        }
        public void DispatchBatchedNegotiationRequests(IUnitOfWork uow, String templateName, String htmlText, IList<RecipientDO> recipients, NegotiationDO negotiationDO)
        {
            if (!recipients.Any())
                return;

            var emailDO = new EmailDO();
            //This means, when the customer replies, their client will include the bookingrequest id
            emailDO.TagEmailToBookingRequest(negotiationDO.BookingRequest);

            var customer = negotiationDO.BookingRequest.Customer;
            var mode = _user.GetMode(customer);
            if (mode == CommunicationMode.Direct)
            {
                var directEmailAddress = _configRepository.Get("EmailFromAddress_DirectMode");
                var directEmailName = _configRepository.Get("EmailFromName_DirectMode");
                emailDO.From = uow.EmailAddressRepository.GetOrCreateEmailAddress(directEmailAddress);
                emailDO.FromName = directEmailName;
            }
            else
            {
                var delegateEmailAddress = _configRepository.Get("EmailFromAddress_DelegateMode");
                var delegateEmailName = _configRepository.Get("EmailFromName_DelegateMode");
                emailDO.From = uow.EmailAddressRepository.GetOrCreateEmailAddress(delegateEmailAddress);
                emailDO.FromName = String.Format(delegateEmailName, customer.DisplayName);
            }

            emailDO.Subject = string.Format("Need Your Response on {0} {1} event: {2}",
                negotiationDO.BookingRequest.Customer.FirstName,
                (negotiationDO.BookingRequest.Customer.LastName ?? ""),
                "RE: " + negotiationDO.Name);

            var responseUrl = String.Format("NegotiationResponse/View?negotiationID={0}", negotiationDO.Id);

            var tokenUrls = new List<String>();
            foreach (var attendee in recipients)
            {
                emailDO.AddEmailRecipient(EmailParticipantType.To, attendee.EmailAddress);
                var curUserDO = uow.UserRepository.GetOrCreateUser(attendee.EmailAddress);
                var tokenURL = uow.AuthorizationTokenRepository.GetAuthorizationTokenURL(responseUrl, curUserDO);
                tokenUrls.Add(tokenURL);
            }

            uow.EmailRepository.Add(emailDO);
            var summaryQandAText = _negotiation.GetSummaryText(negotiationDO);

            string currBookerAddress = negotiationDO.BookingRequest.Booker.EmailAddress.Address;

            var conversationThread = _br.GetConversationThread(negotiationDO.BookingRequest);

            // Fix an issue when coverting to UTF-8
            conversationThread = conversationThread.Replace((char)160, (char)32);

            uow.EnvelopeRepository.ConfigureTemplatedEmail(emailDO, templateName,
                new Dictionary<string, object>
                {
                    {"RESP_URL", tokenUrls},
                    {"bodytext", htmlText},
                    {"questions", String.Join("<br/>", summaryQandAText)},
                    {"conversationthread", conversationThread},
                    {"bookername", currBookerAddress.Replace("@kwasant.com","")}
                });

            negotiationDO.NegotiationState = NegotiationState.AwaitingClient;

            //Everyone who gets an email is now an attendee.
            var currentAttendeeIDs = negotiationDO.Attendees.Select(a => a.EmailAddressID).ToList();
            foreach (var recipient in recipients)
            {
                if (!currentAttendeeIDs.Contains(recipient.EmailAddressID))
                {
                    var newAttendee = new AttendeeDO
                    {
                        EmailAddressID = recipient.EmailAddressID,
                        Name = recipient.EmailAddress.Name,
                        NegotiationID = negotiationDO.Id
                    };
                    uow.AttendeeRepository.Add(newAttendee);
                }
            }
        }