Example #1
0
        public ActionResult SendEmail(string userID, string accountID, string emailID, string name, string filename, string accountEmail, string resendInvite)
        {
            string code          = UserManager.GenerateEmailConfirmationToken(userID);
            var    body          = "";
            string savedFileName = string.Empty;
            string imagesUrl     = ConfigurationManager.AppSettings["IMAGE_HOSTING_SERVICE_URL"];
            int    accountId     = 0;

            int.TryParse(accountID, out accountId);
            string accountAddress = accountService.GetPrimaryAddress(new GetAddressRequest()
            {
                AccountId = accountId
            }).Address;
            string accountPhoneNumber = accountService.GetPrimaryPhone(new GetPrimaryPhoneRequest()
            {
                AccountId = accountId
            }).PrimaryPhone;
            string accountLogo = string.Empty;
            string accountName = string.Empty;
            string subject     = string.Empty;

            ApplicationServices.Messaging.Accounts.GetAccountImageStorageNameResponse response = accountService.GetStorageName(new ApplicationServices.Messaging.Accounts.GetAccountImageStorageNameRequest()
            {
                AccountId = accountId
            });
            if (response.AccountLogoInfo.SubscriptionId == 3)
            {
                string templateName = string.Empty;
                if (string.IsNullOrEmpty(resendInvite))
                {
                    templateName = EmailTemplate.BDXUserRegistration.ToString() + ".txt";
                }
                else
                {
                    templateName = EmailTemplate.BDXResendInvite.ToString() + ".txt";
                }
                savedFileName = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["EMAILTEMPLATES_PHYSICAL_PATH"].ToString(), templateName);
                subject       = "BDX Lead Management - New User Creation Notification – " + response.AccountLogoInfo.AccountName + " : " + name;
            }
            else
            {
                savedFileName = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["EMAILTEMPLATES_PHYSICAL_PATH"].ToString(), filename);
            }
            if (!String.IsNullOrEmpty(response.AccountLogoInfo.StorageName))
            {
                accountLogo = urlService.GetUrl(accountId, ImageCategory.AccountLogo, response.AccountLogoInfo.StorageName);
            }
            else
            {
                accountLogo = "";
            }
            accountName = response.AccountLogoInfo.AccountName;
            if (response.AccountLogoInfo.SubscriptionId != 3)
            {
                subject = "SmartTouch New User Creation Notification – " + accountName + " : " + name;
            }
            string accountImage = string.Empty;

            if (!string.IsNullOrEmpty(accountLogo))
            {
                accountImage = accountImage + "<td align='right' valign='center' style='margin:0px;padding:0px 0px 25px 0px;'><img src='" + accountLogo + "' alt='" + accountName + "' style='width:100px;' width='100'> </td>";
            }
            else
            {
                accountImage = "";
            }
            using (StreamReader reader = new StreamReader(savedFileName))
            {
                do
                {
                    var protectedUserId    = MachineKey.Protect(GetBytes(userID));
                    var protectedAccountId = MachineKey.Protect(GetBytes(accountID));
                    var protectedEmailId   = MachineKey.Protect(GetBytes(emailID));
                    var securedUserID      = Convert.ToBase64String(protectedUserId);
                    var securedAccountID   = Convert.ToBase64String(protectedAccountId);
                    var securedEmailID     = Convert.ToBase64String(protectedEmailId);
                    var user = UserExtensions.ToFirstName(this.Identity) + " " + UserExtensions.ToLastName(this.Identity);
                    body = reader.ReadToEnd().Replace("[USERNAME]", UserExtensions.ToUserName(this.Identity)).Replace("[ACCOUNTNAME]", accountName).Replace("[USER]", user).Replace("[ACCOUNTID]", Url.Encode(securedAccountID)).Replace("[NAME]", name).Replace("[EMAILID]", Url.Encode(securedEmailID)).Replace("[NEWUSEREMAIL]", emailID).Replace("[GUID]", code).Replace("[USERID]", Url.Encode(securedUserID)).Replace("[STURL]", Request.Url.Authority.ToLower()).Replace("[ADDRESS]", accountAddress).Replace("[PHONE]", accountPhoneNumber).Replace("[IMAGES_URL]", imagesUrl).Replace("[AccountImage]", accountImage);
                }while (!reader.EndOfStream);
            }
            var result = default(int);

            int.TryParse(accountID, out result);
            Dictionary <Guid, string> providerDetails = accountService.GetTransactionalProviderDetails(this.Identity.ToAccountID());
            string fromEmail = string.IsNullOrEmpty(providerDetails.FirstOrDefault().Value) ? accountEmail : providerDetails.FirstOrDefault().Value;

            if (providerDetails.FirstOrDefault().Key != null)
            {
                UserManager.SendEmail(userID, subject + "|" + fromEmail + "|" + result + "|" + providerDetails.FirstOrDefault().Key + "|" + Request.Url.Authority.ToLower(), body);
            }
            return(Json(new
            {
                success = true,
                response = "[|Email has been sent to you Please check your Email.|]"
            }, JsonRequestBehavior.AllowGet));
        }