Ejemplo n.º 1
0
        public string ParseTemplate(SendEmailAction emailAction, object model, string subject)
        {
            string layoutPath  = Path.Combine(_templateFolder, "Partial\\Layout.cshtml");
            string partialPath = Path.Combine(_templateFolder, string.Format("{0}.cshtml", emailAction.TemplateId));

            string layoutHtml  = Parse(layoutPath, model);
            string partialHtml = Parse(partialPath, model);

            var builder = new StringBuilder(layoutHtml);

            builder.Replace("**partial**", partialHtml);
            builder.Replace("**subject**", subject);

            return(builder.ToString());
        }
Ejemplo n.º 2
0
        public static void Send(SendEmailAction emailAction, string subject, string body)
        {
            using (MailMessage message = new MailMessage())
            {
                foreach (var mailAddress in emailAction.EmailToList)
                {
                    message.To.Add(mailAddress.Email);
                }

                message.Subject         = subject;
                message.SubjectEncoding = Encoding.UTF8;
                message.Body            = body;
                message.IsBodyHtml      = true;
                message.BodyEncoding    = Encoding.UTF8;

                using (var client = new SmtpClient())
                    client.Send(message);
            }
        }
Ejemplo n.º 3
0
        private async Task EmailInsert <T>(Guid accountId, EmailTemplate templateId, string email, T model) where T : new()
        {
            var action = new SendEmailAction()
            {
                TemplateId  = templateId,
                EmailToList = new List <XmlEmail>()
                {
                    new XmlEmail {
                        Email = email
                    }
                }
            };

            string actionXml = XMLSerializer.SerializeObject(action);
            string modelXml  = XMLSerializer.SerializeObject(model);

            using (var respository = new SaaS.Identity.EmailRepository())
                await respository.EmailInsertAsync(accountId, Status.NotStarted, actionXml, modelXml);
        }
Ejemplo n.º 4
0
        public string ParseSubject(SendEmailAction emailAction, object model)
        {
            string subject = _resourceManager.GetString(emailAction.TemplateId.ToString());

            if (!string.IsNullOrEmpty(subject))
            {
                var type        = model.GetType();
                var productName = type.GetProperty("ProductName", BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

                if (!object.Equals(productName, null))
                {
                    var value = productName.GetValue(model, null) as string;

                    subject = subject.Replace("[product name]", value);
                    subject = subject.Replace("[Product Name]", value); //say hello for Ksenia
                }
            }

            return(string.IsNullOrEmpty(subject) ? "SaaS" : subject);
        }
Ejemplo n.º 5
0
        public string ParseTemplateAsync(SendEmailAction emailAction, string xml, out object model)
        {
            model = null;
            switch (emailAction.TemplateId)
            {
            case EmailTemplate.EmailChangeConfirmationNotification:
                model = XMLSerializer.DeserializeObject <EmailChangeConfirmationNotification>(xml); break;

            case EmailTemplate.eSignEmailConfirmationNotification:
            case EmailTemplate.EmailConfirmationLateNotification:

                var emailConfirmation           = XMLSerializer.DeserializeObject <EmailConfirmationNotification>(xml);
                var emailConfirmationUriBuilder = new UriBuilder(_appSettigns.Oauth.EmailConfirmation);
                var emailConfirmationQuery      = HttpUtility.ParseQueryString(emailConfirmationUriBuilder.Query);
                emailConfirmationQuery.Add("userId", emailConfirmation.AccountId.ToString("N"));
                emailConfirmationUriBuilder.Query = emailConfirmationQuery.ToString();

                emailConfirmation.ConfirmationLink = emailConfirmationUriBuilder.Uri.ToString();

                model = emailConfirmation;

                break;

            case EmailTemplate.EmailConfirmationCovermountNotification:
            case EmailTemplate.EmailConfirmationNotification: model = XMLSerializer.DeserializeObject <EmailConfirmationNotification>(xml); break;

            case EmailTemplate.EmailChangeNotification: model = XMLSerializer.DeserializeObject <EmailChangeNotification>(xml); break;

            case EmailTemplate.ProductSuspendNotification: model = XMLSerializer.DeserializeObject <ProductSuspendNotification>(xml); break;

            case EmailTemplate.AccountCreationCompleteNotification:
            case EmailTemplate.RecoverPasswordNotification: model = XMLSerializer.DeserializeObject <RecoverPasswordNotification>(xml); break;

            case EmailTemplate.ProductAssignedNotification:
            case EmailTemplate.ProductAssignedNotificationCreatePassword:
            case EmailTemplate.ProductEditionAssignedNotification:
            case EmailTemplate.ProductEditionAssignedNotificationCreatePassword:
            case EmailTemplate.ProductUnassignedNotification: model = XMLSerializer.DeserializeObject <ProductAssignedNotification>(xml); break;

            case EmailTemplate.ProductRenewalOffNotification: model = XMLSerializer.DeserializeObject <ProductRenewalOffNotification>(xml); break;

            case EmailTemplate.WelcomeFreeProductNotification:
            case EmailTemplate.WelcomeFreeProductCovermountNotification:
                model = XMLSerializer.DeserializeObject <WelcomeFreeProductNotification>(xml); break;

            case EmailTemplate.WelcomePurchaseNotification:
            case EmailTemplate.WelcomePurchaseHomePlanNotification:
            case EmailTemplate.WelcomePurchasePremiumPlanNotification:
            case EmailTemplate.WelcomePurchaseBasicPlanNotification:
            case EmailTemplate.WelcomePurchaseHomeEditionNotification:
            case EmailTemplate.WelcomePurchaseProEditionNotification:
            case EmailTemplate.WelcomePurchasePremiumEditionNotification:
            case EmailTemplate.WelcomePurchaseEnterpriseNotification:
            case EmailTemplate.MicrotransactionCreatePasswordNotification:
            case EmailTemplate.WelcomePurchaseProOcrEditionNotification:      //pdfsam
            case EmailTemplate.WelcomePurchaseStandardEditionNotification:    //pdfsam
            case EmailTemplate.WelcomePurchaseStandardPlanNotification:       //pdfsam
            case EmailTemplate.WelcomePurchaseProPlanNotification:            //pdfsam
            case EmailTemplate.WelcomePurchaseProOcrPlanNotification:         //pdfsam
            case EmailTemplate.WelcomePurchaseOcrPlanNotification:            //pdfsam
            case EmailTemplate.WelcomePurchaseEditPlanNotification:           //pdfsam
            case EmailTemplate.WelcomePurchaseConvertPlanNotification:        //pdfsam
            case EmailTemplate.WelcomePurchaseMigrationFromSuiteNotification: //pdfsuite to soda

                var welcomeModel = XMLSerializer.DeserializeObject <WelcomePurchaseNotification>(xml);

                var uriBuilder = new UriBuilder(_appSettigns.Oauth.CreatePassword);
                if (emailAction.TemplateId == EmailTemplate.WelcomePurchaseMigrationFromSuiteNotification)
                {
                    uriBuilder = new UriBuilder(new Uri(string.Format(_appSettigns.Oauth.CustomLink, "online-createpassword-suite-to-soda")));
                }
                var query = HttpUtility.ParseQueryString(uriBuilder.Query);

                query.Add("userId", welcomeModel.AccountId.ToString("N"));
                query.Add("email", welcomeModel.Email);
                query.Add("firstName", welcomeModel.FirstName);
                query.Add("lastName", welcomeModel.LastName);

                uriBuilder.Query = query.ToString();

                welcomeModel.CreatePasswordLink = uriBuilder.Uri.ToString();

                model = welcomeModel;

                break;

            case EmailTemplate.LegacyCreatePasswordReminder:
            case EmailTemplate.LegacyActivationCreatePasswordNotification:
                model = XMLSerializer.DeserializeObject <CreatePasswordNotification>(xml); break;

            case EmailTemplate.MergeConfirmationNotification:
                model = XMLSerializer.DeserializeObject <MergeConfirmationNotification>(xml); break;

            case EmailTemplate.eSignSignPackageNotification: model = XMLSerializer.DeserializeObject <XmlNotification>(xml); break;

            default: model = XMLSerializer.DeserializeObject <Notification>(xml); break;
            }

            var subject = ParseSubject(emailAction, model);

            return(ParseTemplate(emailAction, model, subject));
        }