Ejemplo n.º 1
0
        public async Task <ActionResult> IndexAsync(CancellationToken cancellationToken)
        {
            var result = await new AuthorizationCodeMvcApp(this, new GmailAppFlowMetadata()).
                         AuthorizeAsync(cancellationToken);

            if (result.Credential != null)
            {
                var service     = GMailHelper.InitilizeService(result.Credential);
                var lstMessages = GMailHelper.ListInboxMessages(service, "Save");
                foreach (var objMessage in lstMessages)
                {
                    GMailHelper.ProcessMessage(service, objMessage.Id);
                }
                string msg = lstMessages.Count > 0 ? "" : "No more mail to Synchronize";
                if (Request.HttpMethod == "GET")
                {
                    return(RedirectToAction("SynchSuccess", "Home"));
                }
                else
                {
                    return(Json(new { status = "success", message = msg }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { status = "failed", redirectURL = result.RedirectUri }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        public string GetCodeFromMessage(string senderNickname, string userId)
        {
            var messageSnippet         = GMailHelper.ReadLastInboxMessage(senderNickname, userId);
            var startWith              = "following code";
            var substring              = messageSnippet.Substring(messageSnippet.IndexOf(startWith, StringComparison.Ordinal) + startWith.Length);
            var orderConfirmationArray = substring.Trim().Split(new char[] { ' ', '.', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            return(orderConfirmationArray[0]);
        }
Ejemplo n.º 3
0
 public ActionResult MailSync()
 {
     try
     {
         var service     = GMailHelper.InitilzeServiceByServiceAccount();
         var lstMessages = GMailHelper.ListInboxMessages(service, "Save");
         foreach (var objMessage in lstMessages)
         {
             GMailHelper.ProcessMessage(service, objMessage.Id);
         }
         string msg = lstMessages.Count > 0 ? string.Format("{0} mail(s) synchronized.", lstMessages.Count) : "No more mail to synchronize";
         return(Json(new { status = "success", message = msg }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { status = "failed", message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 4
0
        public void CloseReporterAndSendMessage()
        {
            try
            {
                Extent.Close();

                var senderNickname = "Lizy Flower";
                var from = "*****@*****.**";
                var to = "*****@*****.**";
                var subject = "Test results!";
                var body = "Test run is over! The report is attached to the letter.";
                var attachmentPath = "ExtentReports.html";
                GMailHelper.SendMessageWithAttachment(senderNickname, from, to, subject, body, attachmentPath);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }