// creates a list of all current emails and determines if any of the emails is from pinnacledistro.com public void RunGoogleAPI() { // this is the date element passed to know which days to check for new emails. string date = DateTime.Now.ToString("yyyy/MM/dd"); List <Google.Apis.Gmail.v1.Data.Message> messageList = googleAPI.GetMessageList(string.Format("from:[email protected] in:inbox after:{0}", date)); Google.Apis.Gmail.v1.Data.Message message; // for all messages in the messageList iterate through and check if the email Id exists in our listing. for (int i = 0; i < messageList.Count; i++) { string subject = ""; string value = emailIdList.Where(x => x.Contains(messageList[i].Id)).FirstOrDefault(); // if the string value is null then it does not exist in the emails sent list so it will need to be sent // however we need to do a check inside of getNewEmail so we can determine if the email will be sent as a // lead or as a order. if (string.IsNullOrEmpty(value)) { // return value of email message message = googleAPI.GetMessage(messageList[i].Id); // return message subject subject = googleAPI.GetEmailSubject(message); // This will build the BashFile to update zendesk with the new lead. if (subject.Contains("New customer registration")) { BuildBashFile(messageList[i].Id); } // this for now is emailing the salesrep with a new order purchase. // I want this to create a bashfile that will udpate zendesk with the // correct order information. else if (subject.Contains("Purchase Receipt for Order")) { // I will also have this email me personally with the information of the bash file // this will allow me ot better understand who and when the project added the values. List <string> productList = ZenOrder.ConvertToLineItems(message, googleAPI); ZenOrder.ConvertToCartWithProducts(productList); } // return body string body = googleAPI.GetEmailBody(message); } } }
// This will take the html body of an email with order details // and parse information into a list that can be used in a // quick manner. public List <string> ConvertToLineItems(Google.Apis.Gmail.v1.Data.Message message, GoogleAPI googleAPI) { string body = FormatBody(googleAPI.GetEmailBody(message)); string[] words = RemoveBrackets(body); List <string> productList = RemoveSkus(words); productList = FormatProductList(productList); return(productList); }