public string EmailTemplate(string to, string content, Settings settings) { using (var sr = File.OpenText(HostingEnvironment.MapPath(@"~/Content/Emails/EmailNotification.htm"))) { var sb = sr.ReadToEnd(); sr.Close(); sb = sb.Replace("#CONTENT#", content); sb = sb.Replace("#SITENAME#", settings.ForumName); sb = sb.Replace("#SITEURL#", settings.ForumUrl); if (!string.IsNullOrEmpty(to)) { to = $"<p>{to},</p>"; sb = sb.Replace("#TO#", to); } return sb; } }
public void SendMail(Email email, Settings settings) { SendMail(new List<Email> { email }, settings); }
public void SendMail(List<Email> emails, Settings settings) { // Add all the emails to the email table // They are sent every X seconds by the email sending task foreach (var email in emails) { // Sort local images in emails email.Body = StringUtils.AppendDomainToImageUrlInHtml(email.Body, settings.ForumUrl.TrimEnd('/')); Add(email); } }
public void UpdateSavesTheNewSettings() { try { var configPath = Path.Combine(Folders.DataDirectory, "web.settings"); var fileSystemMock = new Mock<FileSystem>(MockBehavior.Strict); var writer = new StringWriter(); fileSystemMock.Setup(fs => fs.WriteToFile(configPath)).Returns(writer); Manager.Reset(); Manager.FileSystem = fileSystemMock.Object; var newSettings = new Settings(); newSettings.Servers.Add(new Server { DisplayName = "AServer", Uri = "http://somewhere" }); newSettings.ReportLevels.Add(new ReportLevel { Target = ActionHandlerTargets.Root }); newSettings.ReportLevels[0].Reports.Add(new Report { DisplayName = "A Test Report", ActionName = "aReport", IsDefault = true }); Manager.Update(newSettings); var actualXaml = writer.GetStringBuilder().ToString(); var expectedXaml = "<Settings xmlns=\"urn:cruisecontrol:web:config\">" + Environment.NewLine + " <Settings.ReportLevels>" + Environment.NewLine + " <ReportLevel Target=\"Root\">" + Environment.NewLine + " <Report ActionName=\"aReport\" DisplayName=\"A Test Report\" IsDefault=\"True\" />" + Environment.NewLine + " </ReportLevel>" + Environment.NewLine + " </Settings.ReportLevels>" + Environment.NewLine + " <Settings.Servers>" + Environment.NewLine + " <Server DisplayName=\"AServer\" Uri=\"http://somewhere\" />" + Environment.NewLine + " </Settings.Servers>" + Environment.NewLine + "</Settings>"; Assert.That(actualXaml, Is.EqualTo(expectedXaml)); Assert.That(Manager.Current, Is.SameAs(newSettings)); } finally { Manager.Reset(); } }