protected override void Initialize() { base.Initialize(); funds = new List <MutualFund>(); cookies = new CookieContainer(); configObj = Config as MutualFundCreationConfig; try { service = EWSUtility.CreateService(new System.Net.NetworkCredential(configObj.MailUsername, configObj.MailPassword, configObj.MailDomain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); app = new Ric.Util.ExcelApp(false, false); if (app.ExcelAppInstance == null) { Logger.Log("Excel cannot be started", Logger.LogType.Error); } titles = new List <string>() { "MNEM", "NAME", "FUND FAMILY", "SEQN", "LOC", "SECD", "ISIN", "BDATE" }; } catch (Exception ex) { Logger.Log("Initialization failed. Ex: " + ex.Message); throw new Exception("Cannot initialize"); } }
/// <summary> /// Sending Email with the newly created CSV attached /// </summary> /// <param></param> /// <returns></returns> private void SendEmail() { try { List <string> mailCC = new List <string>(); List <string> attachement = new List <string>(); StringBuilder bodyBuilder = new StringBuilder(); string body = String.Empty; string title = String.Format("MUTUAL FUND {0}", DateTime.Now.ToString("dd/MM/yy")); bodyBuilder.Append("<p>"); foreach (string signatureLine in configObj.MailSignature) { bodyBuilder.AppendFormat("{0}<br />", signatureLine); } bodyBuilder.Append("</p>"); body = bodyBuilder.ToString(); attachement.Add(String.Format("{0}Results_{1}.xls", configObj.ResultFilePath, resultFileName)); if (configObj.MailCC.Count > 1 || (configObj.MailCC.Count == 1 && configObj.MailCC[0] != "")) { mailCC = configObj.MailCC; } EWSUtility.CreateAndSendMail(service, configObj.MailTo, mailCC, new List <string>(), title, body, attachement); } catch (Exception ex) { string msg = "Cannot send mail :" + ex; Logger.Log(msg, Logger.LogType.Error); } }
protected override void Initialize() { configObj = Config as HKIPONDAConfig; EmailAccountInfo emailAccount = EmailAccountManager.SelectEmailAccountByAccountName(configObj.AccountName.Trim()); accountName = emailAccount.AccountName; password = emailAccount.Password; domain = emailAccount.Domain; mailAdress = emailAccount.MailAddress; listMailTo = configObj.MailTo; listMailSignature = configObj.MailSignature; strTxtFilePath = configObj.TxtFilePath; strDownloadFilePath = configObj.FtpFilePath.Trim(); service = EWSUtility.CreateService(new System.Net.NetworkCredential(accountName, password, domain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); strGetYesdayTxtFile = Path.Combine(strTxtFilePath, DateTime.Now.ToUniversalTime().AddHours(+8).AddDays(-1).ToString("MMdd") + "All_HK_IPO_IDN.txt"); strGeneratedTodayTxtFile = Path.Combine(strTxtFilePath, DateTime.Now.ToUniversalTime().AddHours(+8).ToString("MMdd") + "Missing_HK_IPO_NDA.txt"); strFileNameOnFtpYesterday = "EM01" + DateTime.Now.ToUniversalTime().AddDays(-1).AddHours(+8).ToString("MMdd") + ".M"; strFileNameOnFtpToday = "EM01" + DateTime.Now.ToUniversalTime().AddHours(+8).ToString("MMdd") + ".M"; strPatternFTP = @"^\S{2}(?<RIC>\S{4,10}\.(HK|HS))\b\s+"; strFileNameReadOnFtpYesterday = "0001" + DateTime.Now.ToUniversalTime().AddDays(-1).AddHours(+8).ToString("MMdd") + ".M"; strFileNameReadOnFtpToday = "0001" + DateTime.Now.ToUniversalTime().AddHours(+8).ToString("MMdd") + ".M"; strFileNameReadOnFtpYesterdayHS = "3200" + DateTime.Now.ToUniversalTime().AddDays(-1).AddHours(+8).ToString("MMdd") + ".M"; strFileNameReadOnFtpTodayHS = "3200" + DateTime.Now.ToUniversalTime().AddHours(+8).ToString("MMdd") + ".M"; }
public ExchangeUtil(string userName, string password, string domain, string urlWSDL = @"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx") { this.userName = userName; this.password = password; this.domain = domain; this.urlWSDL = urlWSDL; service = EWSUtility.CreateService(new System.Net.NetworkCredential(userName, password, domain), new Uri(urlWSDL)); }
/// <summary> /// Sending Email with the newly created CSV attached /// </summary> /// <param></param> /// <returns></returns> private void SendEmail() { try { var mailCC = new List <string>(); var attachement = new List <string>(); string body = String.Empty; string title = String.Empty; if (updatedCountries.Count == 0) { title = "No New Pre-IPO Records Today"; } else { var bodyBuilder = new StringBuilder(); title = "New Pre-IPO Records"; bodyBuilder.Append("Please find the new Pre-IPO records for "); for (int count = 0; count < updatedCountries.Count; count++) { bodyBuilder.Append(updatedCountries[count]); if (updatedCountries.Count >= 2 && count == updatedCountries.Count - 2) { bodyBuilder.Append(" & "); } else if (count != updatedCountries.Count - 1) { bodyBuilder.Append(", "); } else { bodyBuilder.Append("."); } } bodyBuilder.Append("<p>"); foreach (string signatureLine in _configObj.MailSignature) { bodyBuilder.AppendFormat("{0}<br />", signatureLine); } bodyBuilder.Append("</p>"); body = bodyBuilder.ToString(); attachement.Add(_resultFilename); } if (_configObj.MailCC.Count > 1 || (_configObj.MailCC.Count == 1 && _configObj.MailCC[0] != "")) { mailCC = _configObj.MailCC; } EWSUtility.CreateAndSendMail(_service, _configObj.MailTo, mailCC, new List <string>(), title, body, attachement); } catch (Exception ex) { string msg = "Cannot send mail :" + ex; LogMessage(msg, Logger.LogType.Error); } }
/// <summary> /// SendMail /// </summary> /// <param name="service">Login Email</param> /// <param name="subject">subject</param> /// <param name="content">Body</param> /// <param name="attacheFileList">Attachements</param> private void SendMail(ExchangeService service, string subject, string content, List <string> attacheFileList) { StringBuilder bodyBuilder = new StringBuilder(); bodyBuilder.Append(content); bodyBuilder.Append("<p>"); foreach (string signatureLine in configObj.MailSignature) { bodyBuilder.AppendFormat("{0}<br />", signatureLine); } bodyBuilder.Append("</p>"); content = bodyBuilder.ToString(); if (configObj.MailCC.Count > 1 || (configObj.MailCC.Count == 1 && configObj.MailCC[0] != "")) { listMailCC = configObj.MailCC; } EWSUtility.CreateAndSendMail(service, listMailTo, listMailCC, new List <string>(), subject, content, attacheFileList); }
/// <summary> /// SendMail /// </summary> /// <param name="service">Login Email</param> /// <param name="subject">subject</param> /// <param name="content">Body</param> /// <param name="attacheFileList">Attachements</param> private void SendMail(string subject, string content, List <string> attacheFileList) { StringBuilder bodyBuilder = new StringBuilder(); bodyBuilder.Append(content); bodyBuilder.Append("<p>"); foreach (string signatureLine in configObj.MailSignature) { bodyBuilder.AppendFormat("{0}<br />", signatureLine); } bodyBuilder.Append("</p>"); content = bodyBuilder.ToString(); service = EWSUtility.CreateService(new System.Net.NetworkCredential(accountName, password, domain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); if (configObj.MailCC.Count > 1 || (configObj.MailCC.Count == 1 && configObj.MailCC[0] != "")) { listMailCC = configObj.MailCC; } EWSUtility.CreateAndSendMail(service, listMailTo, listMailCC, new List <string>(), subject, content, attacheFileList); }
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"); } }
protected override void Initialize() { base.Initialize(); _configObj = Config as ASIAPreIPOCheckerConfig; _service = EWSUtility.CreateService(new NetworkCredential(_configObj.MailUsername, _configObj.MailPassword, _configObj.MailDomain), new Uri(@"https://apac.mail.erf.thomson.com/EWS/Exchange.asmx")); }
/// <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); } }
protected List <AgentDLInfo> GetListDetails(string toBeCheckedDL, TimeSpan toBeCheckedOffset, DateTime startDate, DateTime endDate) { List <AgentDLInfo> agentDLList = new List <AgentDLInfo>(); try { EWSUtility ewsUtility = new EWSUtility("SMBSPWEB", "]#Uun6~QqN7k@Z}c", "REDMOND", "*****@*****.**"); List <string> lstEmailID = (List <string>)ewsUtility.ExpandDistributionLists(toBeCheckedDL); // List<string> lstEmailID = new List<string>(); // lstEmailID.Clear(); //lstEmailID.Add("*****@*****.**"); //lstEmailID.Add("*****@*****.**"); //lstEmailID.Add("*****@*****.**"); //lstEmailID.Add("v - [email protected]"); //lstEmailID.Add("v - [email protected]"); //lstEmailID.Add("v - [email protected]"); //lstEmailID.Add("v - [email protected]"); //lstEmailID.Add("*****@*****.**"); //lstEmailID.Add("*****@*****.**"); // Temporary fix : The below agent is causing some issue while fetching data from Exchange, The error is "The XML document ended unexpectedly." // The affected team are : MastOpt and CoachNA (since both DLs have the same list of agents) // lstEmailID.Remove("*****@*****.**"); //todo //--End temporary fix 16 Feb 2017 foreach (string agentEmailID in lstEmailID) { GetUserAvailabilityResults freeBusyResults = ewsUtility.Exchange.GetUserAvailability( Enumerable.Repeat(new AttendeeInfo { SmtpAddress = agentEmailID, AttendeeType = MeetingAttendeeType.Required }, 1), new TimeWindow(startDate, endDate), AvailabilityData.FreeBusy, new AvailabilityOptions() { MeetingDuration = 30, RequestedFreeBusyView = FreeBusyViewType.FreeBusy }); AgentDLInfo agentDLInfo = new AgentDLInfo(); agentDLInfo.DLName = toBeCheckedDL; agentDLInfo.EmailId = agentEmailID; if (freeBusyResults.AttendeesAvailability.First().WorkingHours != null) { agentDLInfo.TimeZoneInfo = freeBusyResults.AttendeesAvailability.First().WorkingHours.TimeZone; agentDLInfo.AgentOffset = agentDLInfo.TimeZoneInfo.BaseUtcOffset.ToString(); agentDLInfo.DLOffset = toBeCheckedOffset.ToString(); agentDLInfo.IsBaseOffset = agentDLInfo.TimeZoneInfo.BaseUtcOffset.Equals(toBeCheckedOffset); agentDLInfo.WorkhoursStartTime = freeBusyResults.AttendeesAvailability.First().WorkingHours.StartTime.ToString(); agentDLInfo.WorkhoursEndTime = freeBusyResults.AttendeesAvailability.First().WorkingHours.EndTime.ToString(); } else { agentDLInfo.DLOffset = toBeCheckedOffset.ToString(); agentDLInfo.AgentOffset = "Unknown"; agentDLInfo.TimeZoneInfo = null; agentDLInfo.IsBaseOffset = false; } agentDLList.Add(agentDLInfo); } return(agentDLList); } catch (Exception ex) { lblError.Text = "Some Exception occurs due to invalid DL or due to some another issue."; lblError.Visible = true; return(agentDLList); } }
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); } }