/// <summary> /// ReadEmailTolistRicChain /// </summary> /// <param name="listRicChain"></param> /// <param name="strPattern">pattern</param> /// <param name="strEmailKeyWord">Email title</param> private void ReadEmailTolistRicChain(List <string> listRicChain, string strPattern, string strEmailKeyWord) { try { EWSMailSearchQuery query = new EWSMailSearchQuery("", mailAdress, mailFolder, strEmailKeyWord, "", startDate, endDate); List <EmailMessage> mailList = null; for (int i = 0; i < 5; i++) { try { mailList = EWSMailSearchQuery.SearchMail(service, query); break; } catch { Thread.Sleep(5000); if (i == 4) { throw; } } } if (mailList.Count > 0) { isExistEmail = true; EmailMessage mail = mailList[0]; mail.Load(); strEmailRicChain = TWHelper.ClearHtmlTags(mail.Body.ToString()); Regex regex = new Regex(strPattern); MatchCollection matches = regex.Matches(strEmailRicChain); foreach (Match match in matches) { listRicChain.Add(match.Groups["RIC"].Value); } } } catch (Exception ex) { Logger.Log("Get Data from mail failed. Ex: " + ex.Message); } }
protected override void Initialize() { base.Initialize(); configObj = Config as TGODailyRICCreationRolloverConfig; txtFilePath = configObj.TxtFilePath.ToString().Trim(); dicCalls.Add("A", "Jan"); dicCalls.Add("B", "Feb"); dicCalls.Add("C", "Mar"); dicCalls.Add("D", "Apr"); dicCalls.Add("E", "May"); dicCalls.Add("F", "Jun"); dicCalls.Add("G", "Jul"); dicCalls.Add("H", "Aug"); dicCalls.Add("I", "Sep"); dicCalls.Add("J", "Oct"); dicCalls.Add("K", "Nov"); dicCalls.Add("L", "Dec"); dicPuts.Add("M", "Jan"); dicPuts.Add("N", "Feb"); dicPuts.Add("O", "Mar"); dicPuts.Add("P", "Apr"); dicPuts.Add("Q", "May"); dicPuts.Add("R", "Jun"); dicPuts.Add("S", "Jul"); dicPuts.Add("T", "Aug"); dicPuts.Add("U", "Sep"); dicPuts.Add("V", "Oct"); dicPuts.Add("W", "Nov"); dicPuts.Add("X", "Dec"); txtFileName = DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_TGO.txt"; txtFileNameMissing = DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_ROLLOV.txt"; expirDate = Interaction.InputBox("Click OK and input EXPIR_DATE in the following input box will generate rollover file", "Whether to generate rollover file?", "", 400, 320).ToString(); if (!string.IsNullOrEmpty(expirDate)) { expirDateFormed = TWHelper.DateStringForm(expirDate, "dd-MMM-yy"); monthYear = expirDateFormed.Substring(expirDateFormed.IndexOf('-') + 1, 3).ToUpper() + expirDateFormed.Substring(expirDateFormed.Length - 1, 1); } }
private void FilllistEXLFromEmail() { try { service = EWSUtility.CreateService(new System.Net.NetworkCredential(accountName, password, domain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); EWSMailSearchQuery query; if (string.IsNullOrEmpty(emailDate)) { query = new EWSMailSearchQuery("", mailAdress, mailFolder, "TWWNT_DROP_IFFM Expired RICs Housekeeping Report for TWWNT_DROP", "", dateTime.AddHours(-dateTime.Hour).AddMinutes(-dateTime.Minute), dateTime); } else { startTime = Convert.ToDateTime(emailDate); endTime = startTime.AddDays(+1); query = new EWSMailSearchQuery("", mailAdress, mailFolder, "TWWNT_DROP_IFFM Expired RICs Housekeeping Report for TWWNT_DROP", "", startTime, endTime); } List <EmailMessage> mailList = null; for (int i = 0; i < 5; i++) { try { mailList = EWSMailSearchQuery.SearchMail(service, query); break; } catch { Thread.Sleep(5000); if (i == 4) { throw; } } } if (mailList.Count > 0) { string emailString = string.Empty; EmailMessage mail = mailList[0]; mail.Load(); emailString = TWHelper.ClearHtmlTags(mail.Body.ToString()); string[] emailEXL = emailString.Replace("EXL", "~").Split('~'); foreach (string email in emailEXL.Where(email => email.Trim().StartsWith("("))) { List <string> listTmp; string tmp = email.Substring(email.IndexOf("(") + 1, email.IndexOf(")") - 2).Trim(); switch (tmp) { case "TAIW_INX_WNT": listTmp = new List <string> { tmp }; RegexPattern(email, listTmp); break; case "TAIW_EQLB_WNT": listTmp = new List <string> { tmp }; RegexPattern(email, listTmp); break; case "TAIW_CBBC": listTmp = new List <string> { tmp }; RegexPattern(email, listTmp); break; case "OTCTWS_WNT": listTmp = new List <string> { tmp }; RegexPattern(email, listTmp); break; case "OTCTWS_INX_WNT": listTmp = new List <string> { tmp }; RegexPattern(email, listTmp); break; } } } else { MessageBox.Show("No email of TWWNT_DROP_IFFM in Outlook!"); } } catch (Exception ex) { Logger.Log("Get Data from mail failed. Ex: " + ex.Message + "Try To Execute {EWSMailSearchQuery.SearchMail(service, query)} 5 times"); } }
/// <summary> /// ReadEmailAndGetData /// </summary> /// <param name="listRic">listRic</param> /// <param name="strPattern">regular expression</param> /// <param name="strEmailKeyWord">subject of email</param> private void ReadEmailTolistRicChain(List <string> listRic, string strPattern, string strEmailKeyWord) { try { service = EWSUtility.CreateService(new System.Net.NetworkCredential(accountName, password, domain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); EWSMailSearchQuery query = null; query = new EWSMailSearchQuery("", mailAdress, mailFolder, strEmailKeyWord, "", startDate, endDate); List <EmailMessage> mailList = null; for (int i = 0; i < 5; i++) { try { mailList = EWSMailSearchQuery.SearchMail(service, query); break; } catch { Thread.Sleep(5000); if (i == 4) { throw; } } } if (mailList.Count > 0) { if (strEmailKeyWord.Equals("TAIFO IFFM - EDA Automation Report")) { isExistFirstEmail = true; } else { isExistSecondEmail = true; } EmailMessage mail = mailList[0]; mail.Load(); strEmailRic = TWHelper.ClearHtmlTags(mail.Body.ToString()); Regex regex = new Regex(strPattern); MatchCollection matches = regex.Matches(strEmailRic); foreach (Match match in matches) { listRic.Add(match.Groups["RIC"].Value); } if (strEmailKeyWord.Equals("TAIFO IFFM - EDA Automation Report")) { countListRic = listRic.Count; if (listRic.Count == 0) { isExistFirstEmptyEmail = true; } } else { if (listRic.Count == countListRic) { isExistSeconEmptydEmail = true; } } } } catch (Exception ex) { Logger.Log("Get Data from mail failed. Ex: " + ex.Message); } }
private List <string> GetRicFromEmail(string emailKeyWord) { List <string> list = new List <string>(); try { service = EWSUtility.CreateService(new System.Net.NetworkCredential(accountName, password, domain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); EWSMailSearchQuery query = query = new EWSMailSearchQuery("", mailAdress, @mailFolder, emailKeyWord, "", startDate, endDate); List <EmailMessage> mailList = null; for (int i = 0; i < 5; i++) { try { mailList = EWSMailSearchQuery.SearchMail(service, query); break; } catch { Thread.Sleep(5000); if (i == 4) { throw; } } } emailCountInMailBox = mailList.Count; if (!(emailCountInMailBox > 0)) { string msg = string.Format("no email in the mailbox. "); Logger.Log(msg, Logger.LogType.Warning); return(null); } string strEmailBody = string.Empty; for (int i = 0; i < emailCountInMailBox; i++) { EmailMessage mail = mailList[i]; mail.Load(); strEmailBody = TWHelper.ClearHtmlTags(mail.Body.ToString()); Regex regex = new Regex(emailPattern); MatchCollection matches = regex.Matches(strEmailBody); foreach (Match match in matches) { if (list.Contains(match.Groups["RIC"].Value)) { continue; } list.Add(match.Groups["RIC"].Value.ToString().Trim()); } } return(list); } catch (Exception ex) { string msg = string.Format("get ric from email error.:{0}", ex.ToString()); Logger.Log(msg, Logger.LogType.Error); return(null); } }