public void Send(NewsletterSubscriber Subscriber) { string content = Publish2(NewsletterMode.Newsletter, null); var Mailings = Subscriber.Mailings.Where(c => c.Newsletter.ID == this.ID); NewsletterMailing Mailing; Mailing = new NewsletterMailing(); Mailing.Site = Subscriber.Site; Mailing.Subscriber = Subscriber; Mailing.Newsletter = this; this.Mailings.Add(Mailing); Mailing.Name = this.Name + "_" + DateTime.Now; Mailing.EmailAddress = Subscriber.Email; Mailing.Save(); string subscriberContent = this.ReplaceSubscriberTags(content, Subscriber, NewsletterMode.Newsletter, Mailing); Mailing.NewsletterSent = EmailManager.SendMail(this.SentFromAddress, Subscriber.Email, this.Subject, subscriberContent, true); Mailing.Save(); }
public string ReplaceAttribute(string attribute, string content, NewsletterMailing mailing) { foreach (Match match in Regex.Matches(content, attribute + "=\"(.*?)\"")) { string hrefValue = match.ToString().Replace(attribute + "=\"", "").Replace("\"", ""); if (!hrefValue.Contains("?subscriber")) { if (!hrefValue.StartsWith("http://")) { if (!hrefValue.StartsWith("/")) { hrefValue = "/" + hrefValue; } hrefValue = Site.DomainName + hrefValue; } hrefValue += "?mailing=" + mailing.ID.ToString(); //subscriber.ID.ToString(); content = content.Replace(match.ToString(), attribute + "=\"" + hrefValue + "\""); } } return(content); }
public string Publish2(NewsletterMode newsletterMode, NewsletterMailing mailing) { string html = Template.Content; string head = ""; if (newsletterMode != NewsletterMode.Newsletter) { string jQueryVersion = ConfigurationManager.AppSettings["jQueryVersion"]; if (jQueryVersion == null || jQueryVersion == "") { jQueryVersion = "jquery-1.8.2.js"; } string jqueryScriptInclude = String.Format(@" <script type=""text/javascript"" src=""/_js/{0}""></script> ", jQueryVersion); head = jqueryScriptInclude; string jQueryUIVersion = "/_bitPlate/_js/jquery-ui-1.9.1.custom.js"; string jqueryUIScriptInclude = String.Format(@"<script type=""text/javascript"" src=""{0}""></script> ", jQueryUIVersion); head += jqueryUIScriptInclude; head += getHeader(); } foreach (CmsScript script in this.Template.Scripts) { if (script.ScriptType == ScriptTypeEnum.Css) { head += @"<style> " + script.Content + @" </style>"; } } foreach (CmsScript script in this.Scripts) { if (script.ScriptType == ScriptTypeEnum.Css) { head += @"<style> " + script.Content + @" </style>"; } } html = html.Replace("[HEAD]", head); Dictionary <string, string> modulesHtmlByContainerName = new Dictionary <string, string>(); string where = ""; // modules zichtbaar in de template if (this.Template != null) { where = String.Format("FK_Site='{0}' AND (CrossPagesMode=1 AND FK_Template = '{1}')", this.Site.ID, this.Template.ID); BaseCollection <BaseModule> templateModules = BaseCollection <BaseModule> .Get(where, "OrderingNumber"); this.Modules.AddRange(templateModules); //foreach (BaseModule module in templateModules) //{ // if (!modulesHtmlByContainerName.ContainsKey(module.ContainerName)) // { // modulesHtmlByContainerName.Add(module.ContainerName, ""); // } // modulesHtmlByContainerName[module.ContainerName] += module.ConvertToType().Publish2(this); //} } //en alle newsletter modules BaseCollection <BaseModule> newsletterModules = BaseCollection <BaseModule> .Get("FK_Newsletter='" + this.ID + "'", "OrderingNumber"); List <BaseModule> modules = this.Modules.GroupBy(c => c.ID).Select(c => c.FirstOrDefault()).OrderBy(c => c.OrderingNumber).ToList(); foreach (BaseModule module in modules) { if (!modulesHtmlByContainerName.ContainsKey(module.ContainerName)) { modulesHtmlByContainerName.Add(module.ContainerName, ""); } modulesHtmlByContainerName[module.ContainerName] += module.ConvertToType().Publish2(this); } foreach (CmsTemplateContainer container in this.Template.Containers) { string containerContent = ""; modulesHtmlByContainerName.TryGetValue(container.Name, out containerContent); containerContent = "<div id='bitContainer" + container.Name + "' class='bitContainer'>" + containerContent + "</div>"; html = html.Replace("[" + container.Name.ToUpper() + "]", containerContent); } //head += Template.GetHeadContent(); switch (newsletterMode) { case NewsletterMode.GuestOnline: NewsletterSubscriber subscriber = new NewsletterSubscriber(); subscriber.ForeName = "Gast"; subscriber.Gender = Autorisation.BaseUser.SexeEnum.Undefined; html = ReplaceSubscriberTags(html, subscriber, newsletterMode); break; case NewsletterMode.Online: html = ReplaceSubscriberTags(html, mailing.Subscriber, newsletterMode); break; case NewsletterMode.Newsletter: //Het plaatsen van de waardes in een nieuwsbrief gebeurd tijdens het verzenden, omdat elke nieuwsbrief voorzien moet worden van andere gegevens. break; } return(html); }
private string ReplaceSubscriberTags(string content, NewsletterSubscriber subscriber, NewsletterMode showMode, NewsletterMailing mailing = null) { content = content.Replace("[NAME]", (subscriber.Name != "") ? subscriber.Name : subscriber.Email) .Replace("[FORENAME]", subscriber.ForeName) .Replace("[NAMEPREFIX]", subscriber.NamePrefix) .Replace("[COMPANYNAME]", subscriber.CompanyName) .Replace("[DATE]", DateTime.Now.ToString("yyyy-MM-dd / hh:mm:ss")) .Replace("[SEXE]", subscriber.GenderString) .Replace("[BEGINNING]", subscriber.GenderString) .Replace("[LIVEURL]", this.Site.DomainName + "/" + this.RelativeUrl) .Replace("[UNSUBSCRIBEURL]", (mailing != null && this.Site.NewsletterOptOutEmailPage != null) ? this.Site.DomainName + this.Site.NewsletterOptOutEmailPage.RelativeUrl + "?subscriber=" + mailing.Subscriber.ID.ToString() : "") .Replace("[USERCODE]", subscriber.ID.ToString()); if (showMode == NewsletterMode.Online || showMode == NewsletterMode.GuestOnline) { content = content.Replace("{OnlineModeTemplate}", "").Replace("{/OnlineModeTemplate}", ""); content = Regex.Replace(content, "{NewsletterModeTemplate}(.*?){/NewsletterModeTemplate}", ""); } else { content = content.Replace("{NewsletterModeTemplate}", "").Replace("{/NewsletterModeTemplate}", ""); content = Regex.Replace(content, "{OnlineModeTemplate}(.*?){/OnlineModeTemplate}", ""); } //Is er een mailing mee gegeven? if (mailing != null) { content = ReplaceAttribute("href", content, mailing); content = ReplaceAttribute("src", content, mailing); } return(content); }