Пример #1
0
        public void sendConfirmationEmail()
        {
            string emailHtml       = savedEmailHtml;
            int    emailTemplateId = int.Parse(emailTemplateIdString);

            IDataProvider[] someDataProviders = new IDataProvider[2];
            int             bbncUserId        = API.Users.CurrentUser.UserID;
            int             reId       = 1;
            string          CcLastFour = "";
            string          justLast4  = creditCardNumber.Text.Substring(creditCardNumber.Text.Length - 4);

            for (int i = 0; i < creditCardNumber.Text.Length - 3; i++)
            {
                CcLastFour += '*';
            }
            CcLastFour += justLast4;

            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[first_name\]", nameFirst.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[last_name\]", nameLast.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[email_address\]", emailAddress.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[street_address\]", streetAddressInput.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[city\]", city.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[state\]", state.SelectedItem.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[zip_code\]", zipCode.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[phone_number\]", phoneNumber.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[gift_amount\]", donationAmount.Text);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[Gift_Date\]", DateTime.Today.Date.ToString());
            savedEmailHtml = Regex.Replace(savedEmailHtml, @" 12:00:00 AM", "");
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[payment_method\]", creditCardType.Value);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[Last_4_CC\]", CcLastFour);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[gift_solicitor\]", orgName.Value);
            savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[fundraiser_page_url\]", "<a href=" + Request.Url.ToString() + ">" + Request.Url.ToString() + "</a>");

            if (teamName.Value == "")
            {
                savedEmailHtml = Regex.Replace(savedEmailHtml, @"(?=\[if_team_name\]).*?(?<=\[end_if\])", "");
            }
            else
            {
                savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[team_name\]", teamName.Value);
                savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[if_team_name\]", "");
                savedEmailHtml = Regex.Replace(savedEmailHtml, @"\[end_if\]", "");
            }


            EmailTemplate emailTemplate = new EmailTemplate();

            emailTemplate.ClientSitesID = PortalSettings.Current().ClientSitesID;
            emailTemplate.ContentText   = string.Empty;
            emailTemplate.Description   = string.Empty;
            emailTemplate.ID            = 224;
            emailTemplate.Name          = emailTemplateName;
            emailTemplate.Subject       = "Subject";
            emailTemplate.OwnerID       = 0;
            emailTemplate.AuditInfo     = null;

            EMail myEmail = new EMail(emailTemplate);

            myEmail.Name             = "Fund Drive Donation Confirmation";
            myEmail.FromAddress      = fromAddress;
            myEmail.FromDisplayName  = fromName;
            myEmail.Subject          = subject;
            myEmail.ContentHTML      = savedEmailHtml + "<p><a href=\"target=&amp;pid=187&amp;did=0&amp;tab=0\">link</a> | <a href=\"target=&amp;pid=188&amp;did=0&amp;tab=0\"> link </a></p>";
            ExceptionWrap.InnerHtml += "<div>Template ID: " + emailTemplate.ID.ToString() + "</div>";
            myEmail.Save();
            myEmail.Send(emailAddress.Text, fromName, reId, bbncUserId, someDataProviders, this.Page);

            if (additionalRecipients != null)
            {
                string[] recipientArray = additionalRecipients.Split(',');

                foreach (string thisRecipient in recipientArray)
                {
                    myEmail.Send(thisRecipient, fromName, reId, bbncUserId, someDataProviders, this.Page);
                }
            }

            Response.Redirect(Request.Url.AbsoluteUri);
        }