예제 #1
0
        private string SendConfirmationEmail(string code, string userId, string password, string language)
        {
            if (language == "en")
            {
                string confirmationLink = Url.Action("ConfirmEmail",
                                                     "Auth", new
                {
                    userid = userId,
                    code
                }, protocol: HttpContext.Request.Scheme);

                string emailBody = "";

                //using (StreamReader reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Email/accountCreation.html")))
                //{
                //    emailBody = reader.ReadToEnd();
                //    emailBody = emailBody.Replace("^Password^", password, StringComparison.OrdinalIgnoreCase);
                //    emailBody = emailBody.Replace("^Confirm^", confirmationLink, StringComparison.OrdinalIgnoreCase);
                //}

                var templateObj = new EmailTemplateData
                {
                    Password = password,
                    HrefLink = confirmationLink,
                    Url      = AppDomain.CurrentDomain.BaseDirectory,
                    FileName = "Email/accountCreation.html"
                };
                emailBody = EmailTextFormatter.Format(templateObj);

                return(emailBody);
            }
            return("");
        }
 private void AssertCustomisedCustomerSessionBookingTemplate(EmailTemplateData template)
 {
     AssertCustomerSessionBookingTemplateSubject(template.type);
     Assert.That(template.subject, Is.EqualTo("Online Booking confirmation with <<BusinessName>>"));
     Assert.That(template.body, Is.EqualTo(GetCustomisedCustomerSessionBookingTemplateBody()));
     AssertCustomerSessionBookingTemplatePlaceholders(template.placeholders);
 }
예제 #3
0
 protected void AssertDefaultCustomerCourseBookingTemplate(EmailTemplateData template)
 {
     AssertCustomerCourseBookingTemplateSubject(template.type);
     Assert.That(template.subject, Is.EqualTo("Confirmation of Booking with <<BusinessName>>"));
     Assert.That(template.body, Is.EqualTo(GetDefaultCustomerCourseBookingTemplateBody()));
     AssertCustomerCourseBookingTemplatePlaceholders(template.placeholders);
 }
예제 #4
0
        }                                                //set only via Secret Manager

        public Task SendEmailAsync(string email, string subject, string message)
        {
            var data = new EmailTemplateData()
            {
                Subject  = subject,
                MainText = message
            };

            return(Send(data, new List <string>()
            {
                email
            }));
        }
        public static string Format(EmailTemplateData templateObj)
        {
            string emailBody = "";

            using (StreamReader reader = new StreamReader(Path.Combine(templateObj.Url, templateObj.FileName)))
            {
                emailBody = reader.ReadToEnd();
                var compiler  = new FormatCompiler();
                var generator = compiler.Compile(emailBody);
                return(generator.Render(templateObj));
            }
            return("");
        }
예제 #6
0
        public Task SendEmailAsync(string email, string subject, string message, string ctaButtonText = "", string ctaButtonUrl = "", string greeting = "", EmailTemplate template = EmailTemplate.Generic)
        {
            var data = new EmailTemplateData()
            {
                Subject    = subject,
                MainText   = message,
                ButtonText = ctaButtonText,
                ButtonUrl  = ctaButtonUrl,
                Greeting   = greeting
            };

            return(Send(data, new List <string>()
            {
                email
            }, template));
        }
예제 #7
0
        public Task Execute(string apiKey, string subject, string email, string callbackUrl)
        {
            var client       = new SendGridClient(apiKey);
            var templateData = new EmailTemplateData
            {
                CallbackUrl = callbackUrl,
            };
            var msg = new SendGridMessage()
            {
                From       = new EmailAddress("*****@*****.**", this.Options.SendGridUser),
                Subject    = subject,
                TemplateId = "d-d9ef54f346ab40b2ab8ffbf0cec1ffb8",
            };

            msg.SetTemplateData(templateData);
            msg.AddTo(new EmailAddress(email));
            msg.SetClickTracking(false, false);
            return(client.SendEmailAsync(msg));
        }
        internal static void Load(MatchingDbContext context)
        {
            context.AddRange(EmailTemplateData.Create().ToList());
            context.AddRange(EmployerData.Create().ToList());
            context.AddRange(RouteAndPathData.Create().ToList());
            context.AddRange(ProviderVenueData.Create());
            context.AddRange(OpportunityData.Create());
            context.AddRange(ServiceStatusHistoryData.Create().ToList());
            context.AddRange(LearningAimReferenceData.Create().ToList());
            context.AddRange(OpportunityData.CreateReferralSingle());
            context.AddRange(OpportunityData.CreateProvisionGapSingle());
            context.AddRange(OpportunityData.CreateReferralMultiple());
            context.AddRange(OpportunityData.CreateReferralMultipleAndProvisionGap());
            context.AddRange(OpportunityData.CreateReferralSingleAndProvisionGap());
            context.AddRange(OpportunityData.CreateProvidersMultiple());
            context.AddRange(OpportunityData.CreateNReferrals(1000));

            context.SaveChanges();
        }
예제 #9
0
        //
        /// <summary>
        /// GET: CompanyEmailTemplate/Details/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int?companyId, int?incidentTypeId)
        {
            if (!companyId.HasValue || !incidentTypeId.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (!IsValidCompany(companyId.Value))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            EmailTemplateData   _row    = _access.GetByPrimaryKey(companyId.Value, incidentTypeId.Value);

            if (_row == null)
            {
                return(HttpNotFound());
            }
            return(View(_row));
        }
예제 #10
0
        //
        // GET: CompanyEmailTemplate/Edit/5
        public ActionResult Edit(int?companyId, int?incidentTypeId)
        {
            if (!companyId.HasValue || !incidentTypeId.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (!IsValidCompany(companyId.Value))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            EmailTemplateData   _row    = _access.GetByPrimaryKey(companyId.Value, incidentTypeId.Value);

            if (_row == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId      = new SelectList(db.Companies, "CompanyId", "CompanyShortName", _row.CompanyId);
            ViewBag.IncidentTypeId = new SelectList(db.IncidentTypes, "IncidentTypeId", "IncidentTypeShortDesc", _row.IncidentTypeId);
            return(View(_row));
        }
예제 #11
0
        public ActionResult Edit([Bind(Include = "CompanyId,IncidentTypeId,SubjectLine,EmailBody,TimeTemplate,ThanksTemplate,LogTemplate,Template,FromServer")] EmailTemplate emailTemplate)
        {
            if (ModelState.IsValid)
            {
                if (!IsValidCompany(emailTemplate.CompanyId))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
                }
                db.Entry(emailTemplate).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            EmailTemplateAccess _access = new EmailTemplateAccess(db);
            EmailTemplateData   _row    = _access.GetByPrimaryKey(emailTemplate.CompanyId, emailTemplate.IncidentTypeId);

            if (_row == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CompanyId      = new SelectList(db.Companies, "CompanyId", "CompanyShortName", emailTemplate.CompanyId);
            ViewBag.IncidentTypeId = new SelectList(db.IncidentTypes, "IncidentTypeId", "IncidentTypeShortDesc", emailTemplate.IncidentTypeId);
            return(View(_row));
        }
        public async Task <IActionResult> Post(string personId, [FromBody] EmailVerification value)
        {
            value.PersonId = new Guid(personId);
            //check the email address in verification email table
            var emailVerification = repository.Find(null, p => p.Address.Equals(value.Address, StringComparison.OrdinalIgnoreCase))?.Items?.FirstOrDefault();

            //if not null then email address already exists
            if (emailVerification != null)
            {
                ModelState.AddModelError("EmailAddress", "email address already in use");
                return(BadRequest(ModelState));
            }

            value.IsVerified = false;
            try
            {
                //resending
                byte[] time  = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
                byte[] key   = applicationUser.PersonId.ToByteArray();
                string token = Convert.ToBase64String(time.Concat(key).ToArray());

                string confirmationLink = Url.Action("ConfirmEmailAddress",
                                                     "Auth", new
                {
                    emailAddress = value.Address,
                    token        = token
                }, protocol: HttpContext.Request.Scheme);

                string emailBody = "";

                //using (StreamReader reader = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Email/confirm-en.html")))
                //{
                //    emailBody = reader.ReadToEnd();
                //    emailBody = emailBody.Replace("^Confirm^", confirmationLink);
                //}

                var templateObj = new EmailTemplateData
                {
                    HrefLink = confirmationLink,
                    Url      = AppDomain.CurrentDomain.BaseDirectory,
                    FileName = "Email/confirm-en.html"
                };
                emailBody = EmailTextFormatter.Format(templateObj);

                var subject = "Confirm your email address at " + Constants.PRODUCT;

                bool isEmailAllowed = emailSender.IsEmailAllowed();
                if (isEmailAllowed)
                {
                    EmailMessage emailMessage = new EmailMessage();
                    EmailAddress address      = new EmailAddress(value.Person.Name, value.Address);
                    emailMessage.To.Add(address);
                    emailMessage.Body    = emailBody;
                    emailMessage.Subject = subject;
                    await emailSender.SendEmailAsync(emailMessage, null, null, "Outgoing").ConfigureAwait(false);

                    value.IsVerificationEmailSent = true;
                }
                else
                {
                    value.IsVerificationEmailSent = false;
                }
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
            var verificationEmail = await base.PostEntity(value).ConfigureAwait(false);

            return(verificationEmail);
        }
예제 #13
0
        public Task Send(EmailTemplateData templateData, List <string> recipients, EmailTemplate template = EmailTemplate.Generic)
        {
            var email = new MimeMessage();

            email.Sender      = MailboxAddress.Parse(Options.EmailUser);
            email.Sender.Name = "Crowd Order Team";
            foreach (var recipient in recipients)
            {
                email.To.Add(MailboxAddress.Parse(recipient));
            }
            if (_configuration["Environment"].ToLower() != "dev")
            {
                email.Bcc.Add(MailboxAddress.Parse(Options.EmailUser));
            }


            email.Subject = templateData.Subject;
            var    builder = new BodyBuilder();
            string tPath   = Directory.GetCurrentDirectory();
            var    hPath   = Directory.GetCurrentDirectory();

            switch (template)
            {
            case EmailTemplate.Generic:
                hPath += _configuration["EmailPaths:Generic.html"].ToLower();
                tPath += _configuration["EmailPaths:Generic.txt"].ToLower();
                break;

            case EmailTemplate.Welcome:
                hPath += _configuration["EmailPaths:Welcome.html"].ToLower();
                tPath += _configuration["EmailPaths:Welcome.txt"].ToLower();
                break;

            case EmailTemplate.PartnerPlain:
                hPath += _configuration["EmailPaths:Plain.html"].ToLower();
                tPath += _configuration["EmailPaths:Plain.txt"].ToLower();
                break;

            case EmailTemplate.ConnectionEmail:
                hPath += _configuration["EmailPaths:PlainConnect.html"].ToLower();
                tPath += _configuration["EmailPaths:PlainConnect.txt"].ToLower();
                break;

            default:
                hPath += @"\wwwroot\emails\generic.html";
                tPath += @"\wwwroot\emails\Generic.txt";
                break;
            }
            //HTML
            StreamReader str      = new StreamReader(hPath);
            string       mailText = str.ReadToEnd();

            str.Close();
            mailText = mailText
                       .Replace("{{h1}}", templateData.H1)
                       .Replace("{{maintext}}", templateData.MainText)
                       .Replace("{{buttontext}}", templateData.ButtonText)
                       .Replace("{{buttonurl}}", templateData.ButtonUrl)
                       .Replace("{{body}}", templateData.Body)
                       .Replace("{{body2}}", templateData.Body2)
                       .Replace("{{greeting}}", templateData.Greeting)
                       .Replace("{{greeting2}}", templateData.Greeting2);


            builder.HtmlBody = mailText;

            //text
            StreamReader str2      = new StreamReader(tPath);
            string       mailText2 = str2.ReadToEnd();

            str2.Close();
            mailText2 = mailText2
                        .Replace("{{h1}}", templateData.H1)
                        .Replace("{{maintext}}", templateData.MainText)
                        .Replace("{{buttontext}}", templateData.ButtonText)
                        .Replace("{{buttonurl}}", templateData.ButtonUrl)
                        .Replace("{{body}}", templateData.Body)
                        .Replace("{{body2}}", templateData.Body2)
                        .Replace("{{greeting}}", templateData.Greeting)
                        .Replace("{{greeting2}}", templateData.Greeting2);



            builder.TextBody = mailText2;

            email.Body = builder.ToMessageBody();
            using (var smtp = new MailKit.Net.Smtp.SmtpClient())
            {
                smtp.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
                smtp.Authenticate(Options.EmailUser, Options.EmailUserPassword);
                smtp.Send(email);
                smtp.Disconnect(true);
            }

            return(Task.FromResult(true));
        }
예제 #14
0
 public Task SendEmailAsync(List <string> recipients, EmailTemplateData data, EmailTemplate template = EmailTemplate.Generic)
 {
     return(Send(data, recipients, template));
 }
예제 #15
0
        // GET: PartnerConnectController/Details/5
        public ActionResult Details(int id)
        {
            var service = _serviceRepository.FindById(id);
            var url     = service.ConnectUrl;
            var claim   = User.FindFirst(ClaimTypes.NameIdentifier);
            var userId  = Guid.Parse(claim.Value);
            var company = _companyRepository.FindByUserId(userId);

            if (company == null)
            {
                //user has not completed registration
                return(RedirectToAction("Company", "Home", new { returnUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}" }));
            }

            var connect = new PartnerConnection()
            {
                Service   = service,
                UserId    = userId,
                Timestamp = DateTime.UtcNow
            };

            var newConnect = _partnerConnectionRepository.Upsert(ref connect);

            if (newConnect)
            {
                //add to cache
                _partnerConnectionsService.SetConnectionToCache(connect);
                if (service.PartnerSignupType == DataHelpers.PartnerSignupType.Email)
                {
                    //send email to user
                    var email      = _configuration["OverrideConnectionEmails"] != "" ? _configuration["OverrideConnectionEmails"] : connect.Service.Partner.MainContactEmail;
                    var mike       = _configuration["OverrideConnectionEmails"] != "" ? _configuration["OverrideConnectionEmails"] : "*****@*****.**";
                    var recipients = new List <string>()
                    {
                        email, User.Identity.Name, mike
                    };
                    var greeting = $"Hi {connect.Service.Partner.MainContactInformalName},";
                    var body     = $"I'd like to introduce you to {company.ContactFirstName} from {company.Name} who is interested in exploring the rates you offer to Crowd Order's users.";

                    var greeting2 = $"Hi {company.ContactFirstName},";
                    var body2     = $"Please meet {connect.Service.Partner.MainContact} from {connect.Service.Partner.Name} who is well placed to talk you through their offering in more detail. " +
                                    $"I'm sure {connect.Service.Partner.MainContactInformalName}  will reach out shortly to introduce themselves properly and thanks again for using Crowd Order. ";


                    var dynamicTemplateData = new EmailTemplateData
                    {
                        Subject   = "Connection request",
                        Greeting  = greeting,
                        Body      = body,
                        Greeting2 = greeting2,
                        Body2     = body2
                    };

                    ((EmailSender)_emailSender).SendEmailAsync(recipients, dynamicTemplateData, EmailSender.EmailTemplate.ConnectionEmail);
                }
            }

            var model = new PartnerConnectionVM()
            {
                PartnerConnection = connect, Suggestions = _siteDataService.GetSuggestedService(3, 0, connect.Service.Id)
            };

            return(View(model));
        }
예제 #16
0
        public static object RetrieveObjectDefinition(IOrganizationService service, SolutionComponentBase component)
        {
            var componentId = component.ObjectId;

            if (component.Type == SolutionComponentType.Entity)
            {
                return(GetEntityMetadata(service, componentId));
            }
            else if (component.Type == SolutionComponentType.Field)
            {
                return(GetAttributeMetadata(service, component.ParentSolutionComponent.LogicalName, componentId));
            }
            else if (component.Type == SolutionComponentType.Relationship)
            {
                return(GetRelationshipMetadata(service, componentId));
            }
            else if (component.Type == SolutionComponentType.OptionSet)
            {
                return(GetOptionSetMetadata(service, componentId));
            }
            else if (component.Type == SolutionComponentType.EntityKey)
            {
                return(GetEntityKeyMetadata(service, component.ParentSolutionComponent.LogicalName, componentId));
            }
            else if (component.Type == SolutionComponentType.Role)
            {
                var logicalName = new RoleData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToRoleData());
            }
            else if (component.Type == SolutionComponentType.RolePrivilege)
            {
                var logicalName = new RolePrivilegeData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToRolePrivilegeData());
            }
            else if (component.Type == SolutionComponentType.View)
            {
                var logicalName = new ViewData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToViewData());
            }
            else if (component.Type == SolutionComponentType.Workflow)
            {
                var logicalName = new WorkflowData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToWorkflowData());
            }
            else if (component.Type == SolutionComponentType.EmailTemplate)
            {
                var logicalName = new EmailTemplateData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToEmailTemplateData());
            }
            else if (component.Type == SolutionComponentType.Ribbon)
            {
                var logicalName = new RibbonData().EntityLogicalName;
                var data        = GetRibbonData(service, componentId);
                return(data.ToRibbonData());
            }
            else if (component.Type == SolutionComponentType.Chart)
            {
                var logicalName = new ChartData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToChartData());
            }
            else if (component.Type == SolutionComponentType.Form)
            {
                var logicalName = new FormData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToFormData());
            }
            else if (component.Type == SolutionComponentType.WebResource)
            {
                var logicalName = new WebResourceData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToWebResourceData());
            }
            else if (component.Type == SolutionComponentType.Sitemap)
            {
                var logicalName = new SiteMapData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToSiteMap());
            }
            else if (component.Type == SolutionComponentType.ConnectionRole)
            {
                var logicalName = new ConnectionRoleData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToConnectionRoleData());
            }
            else if (component.Type == SolutionComponentType.HierarchyRule)
            {
                var logicalName = new HierarchyRuleData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToHierarchyRuleData());
            }
            else if (component.Type == SolutionComponentType.App)
            {
                var logicalName = new AppData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToAppData());
            }
            else if (component.Type == SolutionComponentType.PluginAssembly)
            {
                var logicalName = new PluginAssemblyData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToPluginAssemblyData());
            }
            else if (component.Type == SolutionComponentType.PluginStep)
            {
                var logicalName = new PluginStepData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToPluginStepData());
            }
            else if (component.Type == SolutionComponentType.RoutingRule)
            {
                var logicalName = new RoutingRuleData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToRoutingRuleData());
            }
            else if (component.Type == SolutionComponentType.ConvertRule)
            {
                var logicalName = new ConvertRuleData().EntityLogicalName;
                return(GetGenericData(service, logicalName, componentId)
                       .ToConvertRuleData());
            }
            return(null);
        }