public void ContatinsOneEmail_SouldReturnOnePosition() { // arrange var email = "*****@*****.**"; var data = "Hello, this is my email " + email; var parser = new EmailParser(); parser.Parse(data); int start = data.IndexOf(email); int end = start + email.Length; var expected = new Dictionary <int, int>(); expected.Add(start, end); // act var actual = parser.Parse(data); // assert Assert.AreEqual(actual.Count, expected.Count); }
public static List <PlainTextSymbol> ParsePlainTextSymbols(string text, bool distinct = false) { var ptSyms = new List <PlainTextSymbol>(); List <IndexRange> idxRangs; ptSyms.AddRange(_emojiParser.Parse(text, out idxRangs)); ptSyms.AddRange(_goodsParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_emailParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_urlParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_ipParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_arabParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_chNumberParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_englishParser.Parse(text, idxRangs, out idxRangs)); ptSyms.AddRange(_chineseParser.Parse(text, idxRangs, out idxRangs)); if (distinct) { for (int i = 0; i < text.Length; i++) { string ptext = text.Substring(i, 1).Trim(); if (ptext.Length == 1) { ptSyms.Add(new PlainTextSymbol(ptext, i, null)); } } } ptSyms.Sort((l, r) => { int diffVal = l.StartIndex.CompareTo(r.StartIndex); if (diffVal == 0) { diffVal = l.Length.CompareTo(r.Length); } return(diffVal); }); if (distinct) { for (int j = 1; j < ptSyms.Count; j++) { var pts1 = ptSyms[j - 1]; var pts2 = ptSyms[j]; if (pts1.StartIndex == pts2.StartIndex && pts1.Length == pts2.Length) { ptSyms.RemoveAt(j); j--; } } } return(ptSyms); }
private static SetupContext SetupEmail(string filename) { var path = $@"{Directory.GetCurrentDirectory()}/Emails/{filename}.html"; var original = new HtmlDocument(); original.Load(path); var parser = new EmailParser(); var parseResult = parser.Parse(original.DocumentNode.OuterHtml); var result = new HtmlDocument(); result.LoadHtml(parseResult.MessageHtml); return(new SetupContext { OriginalHtml = original.DocumentNode.OuterHtml, ParsedHtml = result.DocumentNode.OuterHtml, Quotes = parseResult.Quotes }); }
private bool SentEmail(Hashtable TemplateValue, string TemplateKey) { EmailTemplate emailTemplate = _EmailTemplateDataAccess.GetByQuery("TemplateKey='" + TemplateKey + "'").FirstOrDefault(); EmailParser parser = null; string toEmailAddress = ""; if (emailTemplate == null || emailTemplate.Id == 0) { //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Template not found for key :" + TemplateKey)); return(false); } if (!string.IsNullOrWhiteSpace(emailTemplate.BodyFile)) { parser = new EmailParser(HttpContext.Current.Server.MapPath(emailTemplate.BodyFile), TemplateValue, true); } else if (!string.IsNullOrWhiteSpace(emailTemplate.BodyContent)) { parser = new EmailParser(emailTemplate.BodyContent, TemplateValue, false); } MailMessage message = new MailMessage(); message.Body = parser.Parse(); if (emailTemplate.ToEmail.IndexOf("##") > -1) { EmailParser ToEmailParser = new EmailParser(emailTemplate.ToEmail, TemplateValue, false); message.To.Add(new MailAddress(ToEmailParser.Parse())); toEmailAddress = message.To[0].ToString(); } else { message.To.Add(emailTemplate.ToEmail); toEmailAddress = message.To[0].ToString(); } if (emailTemplate.ReplyEmail.IndexOf("##") > -1) { EmailParser ToEmailParser = new EmailParser(emailTemplate.ReplyEmail, TemplateValue, false); message.ReplyTo = new MailAddress(ToEmailParser.Parse()); toEmailAddress = message.To[0].ToString(); } else { message.ReplyTo = new MailAddress(emailTemplate.ReplyEmail); } if (emailTemplate.FromEmail.IndexOf("##") > -1) { EmailParser ToEmailParser = new EmailParser(emailTemplate.FromEmail, TemplateValue, false); message.From = new MailAddress(ToEmailParser.Parse()); } else { if (!string.IsNullOrWhiteSpace(emailTemplate.FromName)) { message.From = new MailAddress(emailTemplate.FromEmail, emailTemplate.FromName); } else { message.From = new MailAddress(emailTemplate.FromEmail); } } if (!string.IsNullOrWhiteSpace(emailTemplate.BccEmail)) { message.Bcc.Add(emailTemplate.BccEmail); } if (!string.IsNullOrWhiteSpace(emailTemplate.CcEmail)) { message.CC.Add(emailTemplate.CcEmail); } if (emailTemplate.Subject.IndexOf("##") > -1) { EmailParser SubjectParser = new EmailParser(emailTemplate.Subject, TemplateValue, false); message.Subject = SubjectParser.Parse(); } else { message.Subject = emailTemplate.Subject; } //if (Attachments != null) //{ // if (Attachments.Count > 0) // { // foreach (var attachment in Attachments) // { // message.Attachments.Add(attachment); // } // } //} message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; try { SmtpClient client = new SmtpClient(); //GlobalSetting EmailHost = _GlobalSettingDataAccess.GetByQuery(string.Format(" SearchKey ='{0}' and CompanyId ='{1}'", "EmailHost", CompanyId)).FirstOrDefault(); //GlobalSetting EmailHostUsername = _GlobalSettingDataAccess.GetByQuery(string.Format(" SearchKey ='{0}' and CompanyId ='{1}'", "EmailHostUsername", CompanyId)).FirstOrDefault(); //GlobalSetting EmailHostPassword = _GlobalSettingDataAccess.GetByQuery(string.Format(" SearchKey ='{0}' and CompanyId ='{1}'", "EmailHostPassword", CompanyId)).FirstOrDefault(); //GlobalSetting EmailPort = _GlobalSettingDataAccess.GetByQuery(string.Format(" SearchKey ='{0}' and CompanyId ='{1}'", "EmailPort", CompanyId)).FirstOrDefault(); client.Host = "webmail.piiscenter.com"; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "piiscenter.com"); client.Port = 25; client.EnableSsl = false; //message.From = new MailAddress("*****@*****.**"); //message.From = new MailAddress("*****@*****.**"); //Need to user From email of default domain client.Send(message); //SmtpClient client = new SmtpClient(); //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "piiscenter.com"); //client.EnableSsl = false; //client.Send(message); // if (!HttpContext.Current.Request.IsLocal) //{ //SmtpClient client = new SmtpClient(); // client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Rezwan10"); // client.EnableSsl = false; // client.Send(message); // } //SmtpClient smtp = new SmtpClient //{ // Host = "smtp.gmail.com", // //change the port to prt 587. This seems to be the standard for Google smtp transmissions. // Port = 587, // //enable SSL to be true, otherwise it will get kicked back by the Google server. // // EnableSsl = true, // //The following properties need set as well // DeliveryMethod = SmtpDeliveryMethod.Network, // UseDefaultCredentials = false, // Credentials = new NetworkCredential("*****@*****.**", "Inf0rmrcl@ud") //}; //smtp.Send(message); EmailHistory emailHistory = new EmailHistory(); emailHistory.TemplateKey = TemplateKey; emailHistory.ToEmail = toEmailAddress; emailHistory.CcEmail = message.CC.ToString(); emailHistory.BccEmail = message.Bcc.ToString(); emailHistory.FromEmail = message.From.ToString(); emailHistory.EmailBodyContent = message.Body; emailHistory.EmailSubject = message.Subject; emailHistory.EmailSentDate = DateTime.Now; emailHistory.LastUpdatedDate = DateTime.Now; _EmailHistoryDataAccess.Insert(emailHistory); return(true); } catch (Exception ex) { EmailHistory emailHistory = new EmailHistory(); emailHistory.TemplateKey = TemplateKey; emailHistory.ToEmail = toEmailAddress; emailHistory.CcEmail = message.CC.ToString(); emailHistory.BccEmail = message.Bcc.ToString(); emailHistory.FromEmail = message.From.ToString(); emailHistory.EmailBodyContent = message.Body; emailHistory.EmailSubject = message.Subject; emailHistory.LastUpdatedDate = DateTime.Now; _EmailHistoryDataAccess.Insert(emailHistory); //Logger.AddElmah(ex); } return(false); }
private bool SentEmailRemainder(Hashtable TemplateValue, string TemplateKey, List <Attachment> Attachments) { EmailTemplateDataAccess maildata = new EmailTemplateDataAccess(); EmailHistoryDataAccess mailhistory = new EmailHistoryDataAccess(); EmailTemplate emailTemplate = maildata.GetByQuery("TemplateKey='" + TemplateKey + "'").FirstOrDefault(); EmailParser parser = null; string toEmailAddress = ""; if (emailTemplate == null || emailTemplate.Id == 0) { //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Template not found for key :" + TemplateKey)); return(false); } if (!string.IsNullOrWhiteSpace(emailTemplate.BodyFile)) { string FilePath = emailTemplate.BodyFile; FilePath = System.Web.Hosting.HostingEnvironment.MapPath(FilePath); parser = new EmailParser(FilePath, TemplateValue, true); //parser = new EmailParser(HttpContext.Current.Server.MapPath(emailTemplate.BodyFile), TemplateValue, true); } else if (!string.IsNullOrWhiteSpace(emailTemplate.BodyContent)) { parser = new EmailParser(emailTemplate.BodyContent, TemplateValue, false); } MailMessage message = new MailMessage(); message.Body = parser.Parse(); if (emailTemplate.ToEmail.IndexOf("##") > -1) { EmailParser ToEmailParser = new EmailParser(emailTemplate.ToEmail, TemplateValue, false); message.To.Add(new MailAddress(ToEmailParser.Parse())); toEmailAddress = message.To[0].ToString(); } else { message.To.Add(emailTemplate.ToEmail); toEmailAddress = message.To[0].ToString(); } if (emailTemplate.ReplyEmail.IndexOf("##") > -1) { EmailParser ToEmailParser = new EmailParser(emailTemplate.ReplyEmail, TemplateValue, false); message.ReplyTo = new MailAddress(ToEmailParser.Parse()); toEmailAddress = message.To[0].ToString(); } else { message.ReplyTo = new MailAddress(emailTemplate.ReplyEmail); } if (emailTemplate.FromEmail.IndexOf("##") > -1) { EmailParser ToEmailParser = new EmailParser(emailTemplate.FromEmail, TemplateValue, false); message.From = new MailAddress(ToEmailParser.Parse()); } else { message.From = new MailAddress(emailTemplate.FromEmail); } if (!string.IsNullOrWhiteSpace(emailTemplate.BccEmail)) { message.Bcc.Add(emailTemplate.BccEmail); } if (!string.IsNullOrWhiteSpace(emailTemplate.CcEmail)) { message.CC.Add(emailTemplate.CcEmail); } if (emailTemplate.Subject.IndexOf("##") > -1) { EmailParser SubjectParser = new EmailParser(emailTemplate.Subject, TemplateValue, false); message.Subject = SubjectParser.Parse(); } else { message.Subject = emailTemplate.Subject; } if (Attachments != null) { if (Attachments.Count > 0) { foreach (var attachment in Attachments) { message.Attachments.Add(attachment); } } } message.IsBodyHtml = true; message.BodyEncoding = System.Text.Encoding.UTF8; try { //if (HttpContext.Current!=null && HttpContext.Current.Request.IsLocal) //{ //SmtpClient client = new SmtpClient(); //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "piiscenter.com"); //client.EnableSsl = false; //client.Send(message); //} SmtpClient smtp = new SmtpClient { Host = "smtp.gmail.com", //change the port to prt 587. This seems to be the standard for Google smtp transmissions. Port = 587, //enable SSL to be true, otherwise it will get kicked back by the Google server. EnableSsl = true, //The following properties need set as well DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential("*****@*****.**", "Inf0rmrcl@ud") }; smtp.Send(message); EmailHistory emailHistory = new EmailHistory(); emailHistory.TemplateKey = TemplateKey; emailHistory.ToEmail = toEmailAddress; emailHistory.CcEmail = message.CC.ToString(); emailHistory.BccEmail = message.Bcc.ToString(); emailHistory.FromEmail = message.From.ToString(); emailHistory.EmailBodyContent = message.Body; emailHistory.EmailSubject = message.Subject; emailHistory.EmailSentDate = DateTime.Now; emailHistory.LastUpdatedDate = DateTime.Now; mailhistory.Insert(emailHistory); return(true); } catch (Exception ex) { EmailHistory emailHistory = new EmailHistory(); emailHistory.TemplateKey = TemplateKey; emailHistory.ToEmail = toEmailAddress; emailHistory.CcEmail = message.CC.ToString(); emailHistory.BccEmail = message.Bcc.ToString(); emailHistory.FromEmail = message.From.ToString(); emailHistory.EmailBodyContent = message.Body; emailHistory.EmailSubject = message.Subject; emailHistory.LastUpdatedDate = DateTime.Now; mailhistory.Insert(emailHistory); //Logger.AddElmah(ex); } return(false); }
public static Email Read(string text) { return(EmailParser.Parse(text)); }