public void MarkPlaceholderSpans(Dictionary <string, string> allowedPlaceholders) { MarkPlaceholderSpans(); HtmlNodeCollection allTags = HtmlBody.SelectNodes("//*[@class='placeholder2']"); Regex reCleanup = new Regex(@"[\s%]"); if (allTags != null) { foreach (HtmlNode n in allTags) { string key = reCleanup.Replace(n.InnerText, ""); string keyLow = key.ToLower(); if (!allowedPlaceholders.ContainsKey(keyLow)) { string classname = n.GetAttributeValue("class", ""); classname = classname.Replace("placeholder2", "placeholderUnkn"); n.SetAttributeValue("class", classname); } else if (allowedPlaceholders[keyLow] != key && allowedPlaceholders[keyLow].ToUpper() != key && allowedPlaceholders[keyLow].ToLower() != key) { n.InnerHtml = "%" + allowedPlaceholders[keyLow] + "%"; } } } }
public void EmailService(forgetclass link) { try { string HtmlBody; using (StreamReader streamReader = new StreamReader(config["IssuerEmailDetail:HtmlBodyFile"], Encoding.UTF8)) { HtmlBody = streamReader.ReadToEnd(); } HtmlBody = HtmlBody.Replace("JwtToken", link.JwtToken); MailMessage message = new MailMessage(); SmtpClient smtp = new SmtpClient(); message.From = new MailAddress(config["IssuerEmailDetail:Email"]); message.To.Add(new MailAddress(link.Email)); message.Subject = "Reset Password"; message.IsBodyHtml = true; message.Body = HtmlBody; smtp.Port = 587; smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(config["IssuerEmailDetail:Email"], config["IssuerEmailDetail:Password"]); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(message); } catch (Exception e) { throw e; } }
public Html() { _head = new HtmlHead(); _body = new HtmlBody(); this.AddChild(this._body); this.AddChild(this._head); }
public void HtmlTest() { var text = new TextElement(TEST_TEXT, TEST_NAME); var body = new HtmlBody(); var bodyObject = new PrivateObject(body); var expectedText = String.Format("{0}{1}", bodyObject.GetField("_required", BindingFlags.NonPublic | BindingFlags.Static), text.HtmlCode); body.AddElement(text); Assert.AreEqual(expectedText, body.Html); }
public void HeadElementTest() { var textElement = new TextElement(TEST_TEXT, TEST_NAME); var body = new HtmlBody(); body.AddElement(textElement); var headerText = String.Format("<style>{1}{0}{1}</style>{1}", textElement.Style.HtmlCode, Environment.NewLine); Assert.AreEqual(body.HeadElements(), headerText); }
public void ChildPropertyChangedTest() { var hasFiredChanged = false; var text = new TextElement(); var body = new HtmlBody(); body.PropertyChanged += (source, args) => { hasFiredChanged = args.PropertyName == "InnerText" && ((ValuedPropertyChangedEventArgs)args).NewValue == TEST_TEXT; }; body.AddElement(text); text.InnerText = TEST_TEXT; Assert.IsTrue(hasFiredChanged); }
public void AddElementTest() { var hasFiredChanged = false; var text = new TextElement(); var body = new HtmlBody(); var bodyObj = new PrivateObject(body); body.PropertyChanged += (source, args) => { hasFiredChanged = args.PropertyName == HtmlContainer.CHILD_UPDATE_VALUE; }; Assert.IsTrue(body.AddElement(text)); var collection = bodyObj.GetField("_children") as IList <HtmlElement>; Assert.IsTrue(hasFiredChanged); Assert.IsTrue(collection.Contains(text)); Assert.IsTrue(collection.Count == 1); }
private bool IsSnippetEqualsBody() { if (IgnoreHtmlParts) { if (TextBody.Count > 1) { return(false); } return(Equals(TextBody.First(), Snippet)); } if (TextBody?.Count > 1 || HtmlBody?.Count > 1) { return(false); } return(Equals(TextBody?.First(), Snippet) || Equals(HtmlBody?.First(), Snippet)); }
public void ReplaceEmbeddedImages(ILogger log = null) { log = log ?? new NullLogger(); try { var attchments = Attachments.Where(a => a.isEmbedded && !string.IsNullOrEmpty(a.storedFileUrl)).ToList(); if (!attchments.Any()) { return; } foreach (var attach in attchments) { if (!string.IsNullOrEmpty(attach.contentId)) { HtmlBody = HtmlBody.Replace(string.Format("cid:{0}", attach.contentId.Trim('<').Trim('>')), attach.storedFileUrl); } else if (!string.IsNullOrEmpty(attach.contentLocation)) { HtmlBody = HtmlBody.Replace(string.Format("{0}", attach.contentLocation), attach.storedFileUrl); } else { //This attachment is not embedded; attach.contentId = null; attach.contentLocation = null; } } } catch (Exception ex) { log.Error("ReplaceEmbeddedImages() \r\n Exception: \r\n{0}\r\n", ex.ToString()); } }
/// <summary> Crea el cuerpo del Mail a ser enviado /// </summary> /// <param name="receptor"></param> /// <param name="replacements"></param> public void CreateMessage(Receptor receptor, ListDictionary replacements) { var html = HtmlBody.ToString(); if (FuncHtmlParse != null) { html = FuncHtmlParse.Invoke(receptor, html); } Mensaje = Definition.CreateMailMessage(receptor.Email, replacements, html, new System.Web.UI.Control()); //var header = new Attachment(Properties.Resources.logo_agc.ToStream(ImageFormat.Png), "header.png", "image/png") //{ // ContentId = "header" //}; //var footer = new Attachment(Properties.Resources.footer_mail.ToStream(ImageFormat.Png), "footer.png", "image/png") //{ // ContentId = "footer" //}; //Mensaje.Attachments.Add(header); //Mensaje.Attachments.Add(footer); }
public string ToHtml(Card card) { var html = new StringBuilder(); if (!string.IsNullOrEmpty(Prefix)) { html.Append(Prefix); } switch (TokenType) { case EffectTokenType.Attack_Icon: html.Append("<img src='/Images/attack.gif'>"); break; case EffectTokenType.Defense_Icon: html.Append("<img src='/Images/defense.gif'>"); break; case EffectTokenType.Self: html.Append(card.Title); break; case EffectTokenType.Card_Title: //html.AppendFormat("<a href='/Cards/Search?Query=%2Btitle%3A{0}' target='_blank' title='{1}'>{1}</a>", card.Title.UrlEncode(), card.Title); break; case EffectTokenType.Specific_Card: //var specific = (Card)Body; //html.AppendFormat("<a href='/Cards/Details/{0} target='_blank' title={1}'>{1}</a>", specific.Slug, specific.Title); break; case EffectTokenType.Text: case EffectTokenType.Inline_Text: case EffectTokenType.Inline_Prefix: html.Append(HtmlBody.ToString()); break; case EffectTokenType.Flavor_Text: html.AppendFormat("<i>{0}</i>", HtmlBody.ToString()); break; case EffectTokenType.Trigger: { if (TextBody.ToString() == "Shadow:") { html.Append("<br/><img src='/Images/ShadowDivider.png' style='display:block;margin-left:auto;margin-right:auto;width:285px;'/><br/>"); } html.AppendFormat("<strong>{0}</strong>", HtmlBody.ToString()); } break; default: break; } if (!string.IsNullOrEmpty(Suffix)) { html.Append(Suffix); } return(html.ToString()); }
/// <summary> /// Builds the body. /// </summary> /// <param name="body">The body.</param> /// <returns></returns> private static HtmlBody BuildBody(string body, Dictionary<string, LinkedResource> imagedictionary) { Dictionary<string, LinkedResource> dictionary = new Dictionary<string, LinkedResource>(); string str = serverName; string pattern = "href=\"?([^\\\"' >]+)|src=\\\"?([^\\\"' >]+)|background=\\\"?([^\\\"' >]+)"; MatchCollection matchs = Regex.Matches(body, pattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); foreach (Match match in matchs) { if (match.Groups.Count <= 0) { continue; } if ((((match.Groups[1].Value.ToLower().IndexOf("http://") == -1) && (match.Groups[2].Value.ToLower().IndexOf("http://") == -1) && (match.Groups[3].Value.ToLower().IndexOf("http://") == -1)) && (match.Groups[1].Value.ToLower().IndexOf("mailto:") == -1)) && (match.Groups[2].Value.ToLower().IndexOf("mailto:") == -1)) { if (match.Groups[1].Value != "") { if (match.Groups[0].Value.ToLower() == "href=\"/") { if (match.Groups[1].Value.IndexOf("?") == -1) { body = body.Replace(match.Groups[0].Value + "\"", "href=\"" + str + match.Groups[1].Value + "\""); } else { body = body.Replace(match.Groups[0].Value + "\"", "href=\"" + str + match.Groups[1].Value + "\""); } } else if (match.Groups[1].Value.IndexOf("?") == -1) { body = body.Replace("href=\"" + match.Groups[1].Value + "\"", "href=\"" + str + match.Groups[1].Value + "\""); } else { body = body.Replace("href=\"" + match.Groups[1].Value + "\"", "href=\"" + str + match.Groups[1].Value + "\""); } } else { string str4 = "jpg,jpeg,gif,png"; string image = match.Groups[2].Value; if (image == "") { image = match.Groups[3].Value; } string oldValue = image; string str7 = image.Split(new char[] { char.Parse(".") })[image.Split(new char[] { char.Parse(".") }).Length - 1].ToLower(); if (str4.IndexOf(str7) != -1) { LinkedResource resource = imagedictionary[image]; string contentId = resource.ContentId; if (resource != null) { if (!dictionary.ContainsKey(contentId)) { dictionary.Add(contentId, resource); } body = body.Replace(image, "cid:" + contentId); } else { body = body.Replace(oldValue, str + image); } } else { body = body.Replace(oldValue, str + image); } } } } HtmlBody body2 = new HtmlBody(); body2.body = body; body2.linkedRessources = dictionary; return body2; }
private void increaseFontSizeButton_Click(object sender, EventArgs e) { HtmlBody.IncreaseFontSize(); HtmlBody.ApplyTemplate(); }
public void ReplaceEmbeddedImages(ILogger log = null) { log = log ?? new NullLogger(); try { var attchments = Attachments.Where(a => a.isEmbedded && !string.IsNullOrEmpty(a.storedFileUrl)).ToList(); if (!attchments.Any()) { return; } if (HtmlBodyStream.Length > 0) { HtmlBodyStream.Seek(0, SeekOrigin.Begin); var doc = new HtmlDocument(); doc.Load(HtmlBodyStream, Encoding.UTF8); var hasChanges = false; foreach (var attach in attchments) { HtmlNodeCollection oldNodes = null; if (!string.IsNullOrEmpty(attach.contentId)) { oldNodes = doc.DocumentNode.SelectNodes("//img[@src and (contains(@src,'cid:" + attach.contentId.Trim('<').Trim('>') + "'))]"); } if (!string.IsNullOrEmpty(attach.contentLocation) && oldNodes == null) { oldNodes = doc.DocumentNode.SelectNodes("//img[@src and (contains(@src,'" + attach.contentLocation + "'))]"); } if (oldNodes == null) { //This attachment is not embedded; attach.contentId = null; attach.contentLocation = null; continue; } foreach (var node in oldNodes) { node.SetAttributeValue("src", attach.storedFileUrl); hasChanges = true; } } HtmlBodyStream.Seek(0, SeekOrigin.Begin); if (!hasChanges) { return; } HtmlBodyStream.Close(); HtmlBodyStream.Dispose(); HtmlBodyStream = new MemoryStream(); using (var sw = new StreamWriter(HtmlBodyStream, Encoding.UTF8, 1024, true)) { doc.DocumentNode.WriteTo(sw); sw.Flush(); HtmlBodyStream.Seek(0, SeekOrigin.Begin); } HtmlBodyStream.Seek(0, SeekOrigin.Begin); } else { foreach (var attach in attchments) { if (!string.IsNullOrEmpty(attach.contentId)) { HtmlBody = HtmlBody.Replace(string.Format("cid:{0}", attach.contentId.Trim('<').Trim('>')), attach.storedFileUrl); } else if (!string.IsNullOrEmpty(attach.contentLocation)) { HtmlBody = HtmlBody.Replace(string.Format("{0}", attach.contentLocation), attach.storedFileUrl); } else { //This attachment is not embedded; attach.contentId = null; attach.contentLocation = null; } } } } catch (Exception ex) { log.Error("ReplaceEmbeddedImages() \r\n Exception: \r\n{0}\r\n", ex.ToString()); } }