コード例 #1
0
        /*
         * public bool SendActivationEMail(out string errorMsg)
         * {
         *  string activationLink = "http://usmanchohan.co.uk";
         *  //HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Register/Activation.aspx?id=" + ts.Id;
         *
         *  //send-template(string key, string template_name, array template_content, struct message)
         *  dynamic sendParams = new ExpandoObject();
         *  sendParams.key = "Z46-URL8pJppuh8Hv5Ff3A";
         *  sendParams.template_name = "Secret Project Trial Activation";
         *
         *  sendParams.template_content = new List<dynamic>();
         *
         *  sendParams.message = new ExpandoObject();
         *  sendParams.message.subject = "Here's your Secret Project activation email";
         *  sendParams.message.from_email = "*****@*****.**";
         *  sendParams.message.from_name = "Secret Project";
         *
         *  sendParams.message.to = new List<dynamic>();
         *  sendParams.message.to.Add(new ExpandoObject());
         *  sendParams.message.to[0].email = "*****@*****.**";
         *  sendParams.message.to[0].name = "Usman Akram";
         *
         *  sendParams.message.track_opens = true;
         *  //sendParams.message.track_clicks = true;
         *
         *  sendParams.message.global_merge_vars = new List<dynamic>();
         *  sendParams.message.global_merge_vars.Add(new ExpandoObject());
         *  sendParams.message.global_merge_vars[0].name = "NAME";
         *  sendParams.message.global_merge_vars[0].content = "Chohan";
         *
         *  sendParams.message.global_merge_vars.Add(new ExpandoObject());
         *  sendParams.message.global_merge_vars[1].name = "LINK";
         *  sendParams.message.global_merge_vars[1].content = activationLink;
         *
         *  errorMsg = string.Empty;
         *
         *  MandrillError merr = SendMessage(sendParams);
         *
         *  switch (merr)
         *  {
         *      case MandrillError.OK:
         *          return true;
         *
         *      case MandrillError.WebException:
         *      case MandrillError.HttpNotOk:
         *          errorMsg = "There was an issue sending your activation e-mail. Please try again later or call us directly.";
         *          break;
         *
         *      case MandrillError.Invalid:
         *          errorMsg = "Your email address appears to be invalid. Please try again with a valid address, or call us directly.";
         *          break;
         *
         *      case MandrillError.Rejected:
         *          errorMsg = "Your activation email was rejected. Please try again with a valid address, or call us directly.";
         *          break;
         *
         *      case MandrillError.Unknown:
         *          errorMsg = "There was an unknown problem sending your activation email. Please try again, or call us directly.";
         *          break;
         *  }
         *  return false;
         * }
         */

        #endregion Testing Template

        public bool SendRegistrationEmail(PlayersExt model, Controller ctrl)
        {
            SystemSettingsRepository sysRepo = new SystemSettingsRepository();
            var sys = sysRepo.GetSystemSettings();
            //Add this Postfix if it is a TESTING Site.
            string TestSitePostfix = (sys.CurrentDomain.Contains("test") || sys.CurrentDomain.Contains("localhost")) ? "_TestSite" : "";

            dynamic sendParams = new ExpandoObject();

            sendParams.template_name = "tmpRegistration_PlannedLeagueCOPY" + TestSitePostfix;


            // string LeagueHomePage = sys.CurrentDomain + "/" + league.NewsTag;
            string ReferralPageLink = sys.CurrentDomain + "/Refer/" + model.ReferralCode;
            string ReferralLink     = sys.CurrentDomain + "/refercode/" + model.ReferralCode;

            sendParams.template_content = new List <dynamic>();

            sendParams.message         = new ExpandoObject();
            sendParams.message.subject = "Welcome to MAN v FAT Football";
            sendParams.message.to      = new List <dynamic>();
            sendParams.message.to.Add(new ExpandoObject());
            sendParams.message.to[0].email = model.EmailAddress;
            sendParams.message.to[0].name  = model.FullName;

            //sendParams.message.track_opens = true;
            //sendParams.message.track_clicks = true;

            sendParams.message.global_merge_vars = new List <dynamic>();

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[0].name    = "BMI";
            sendParams.message.global_merge_vars[0].content = model.BMI.HasValue ? model.BMI.Value.ToString("N2") : "";

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[1].name    = "BODYFAT";
            sendParams.message.global_merge_vars[1].content = model.BodyFat.HasValue ? model.BodyFat.Value.ToString("N2") : "";

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[2].name    = "LEAGUEHOMEPAGE";
            sendParams.message.global_merge_vars[2].content = //LeagueHomePage;

                                                              sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[3].name    = "WHATSAPPGROUP";
            sendParams.message.global_merge_vars[3].content = //WhatsAppGroupLink;

                                                              sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[4].name    = "MSGNOEMERGENCYDETAILS";
            sendParams.message.global_merge_vars[4].content = GenerateHtml_EmergencyContactDetails(sys, model);

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[5].name    = "REFERRALPAGELINK";
            sendParams.message.global_merge_vars[5].content = ReferralPageLink;

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[6].name    = "REFERRALLINK";
            sendParams.message.global_merge_vars[6].content = ReferralLink;

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[7].name    = "REFERRALCODE";
            sendParams.message.global_merge_vars[7].content = model.ReferralCode;

            ////Get Premium Dashboard Payment Link
            //PlayerPaymentsRepository playerPaymentsRepo = new PlayerPaymentsRepository();
            //var payment = playerPaymentsRepo.GetPremiumDashboardPayment(model.PlayerID, ctrl);

            //sendParams.message.global_merge_vars.Add(new ExpandoObject());
            //sendParams.message.global_merge_vars[5].name = "PAYLINKDASHBOARD";
            //sendParams.message.global_merge_vars[5].content = payment != null ? SecurityUtils.GeneratePayLinkURL(payment.PaylinkID) : "";

            MandrillError merr     = SendMessage(sendParams, sys);
            string        errorMsg = "";

            switch (merr)
            {
            case MandrillError.OK:
                SecurityUtils.AddAuditLog("Mandrill Email Success", "\"Registration Email\" Email Sent To PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress);
                return(true);

            case MandrillError.WebException:
            case MandrillError.HttpNotOk:
                errorMsg = "There was an issue sending your activation e-mail. Please try again later or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Attempt to Send Email To = PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress + " - HttpNotOK: " + errorMsg);
                break;

            case MandrillError.Invalid:
                errorMsg = "Your email address appears to be invalid. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Invalid: " + errorMsg);
                break;

            case MandrillError.Rejected:
                errorMsg = "Your activation email was rejected. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Rejected: " + errorMsg);
                break;

            case MandrillError.Unknown:
                errorMsg = "There was an unknown problem sending your activation email. Please try again, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Registration Email\" Unknown: " + errorMsg);
                break;
            }
            return(false);
        }
コード例 #2
0
        public bool SendForgottenPassword_Email(PlayersExt model, string ResetPasswordLink)
        {
            //
            SystemSettingsRepository sysRepo = new SystemSettingsRepository();
            var sys = sysRepo.GetSystemSettings();
            //Add this Postfix if it is a TESTING Site.
            string TestSitePostfix = (sys.CurrentDomain.Contains("test") || sys.CurrentDomain.Contains("localhost")) ? "_TestSite" : "";

            dynamic sendParams = new ExpandoObject();

            sendParams.template_name = "ForgottenPassword" + TestSitePostfix;

            sendParams.template_content = new List <dynamic>();

            sendParams.message         = new ExpandoObject();
            sendParams.message.subject = "MANvFAT Football Forgotten Password";
            sendParams.message.to      = new List <dynamic>();
            sendParams.message.to.Add(new ExpandoObject());
            sendParams.message.to[0].email = model.EmailAddress;
            sendParams.message.to[0].name  = model.FullName;

            //sendParams.message.track_opens = true;
            //sendParams.message.track_clicks = true;

            sendParams.message.global_merge_vars = new List <dynamic>();

            sendParams.message.global_merge_vars.Add(new ExpandoObject());
            sendParams.message.global_merge_vars[0].name    = "RESETPASSWORDLINK";
            sendParams.message.global_merge_vars[0].content = ResetPasswordLink;

            MandrillError merr     = SendMessage(sendParams, sys);
            string        errorMsg = "";

            switch (merr)
            {
            case MandrillError.OK:
                SecurityUtils.AddAuditLog("Mandrill Email Success", "\"Forgotten Password Email\" Email Sent To PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress);
                return(true);

            case MandrillError.WebException:
            case MandrillError.HttpNotOk:
                errorMsg = "There was an issue sending your activation e-mail. Please try again later or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", " \"Forgotten Password Email\" Attempt to Send Email To = PlayerID: " + model.PlayerID + " Email = " + model.EmailAddress + " - HttpNotOK: " + errorMsg);
                break;

            case MandrillError.Invalid:
                errorMsg = "Your email address appears to be invalid. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Forgotten Password Email\" Invalid: " + errorMsg);
                break;

            case MandrillError.Rejected:
                errorMsg = "Your activation email was rejected. Please try again with a valid address, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Forgotten Password Email\" Rejected: " + errorMsg);
                break;

            case MandrillError.Unknown:
                errorMsg = "There was an unknown problem sending your activation email. Please try again, or call us directly.";
                SecurityUtils.AddAuditLog("Mandrill Email Error", "\"Forgotten Password Email\" Unknown: " + errorMsg);
                break;
            }
            return(false);
        }