Esempio n. 1
0
        public static IEnumerable <Message> ReadImapEmail()
        {
            var mailRepository = new MailRepository(
                ConfigurationManager.AppSettings.Get("EmailServer"),
                Convert.ToInt32(ConfigurationManager.AppSettings.Get("EmailPort")),
                Convert.ToBoolean(ConfigurationManager.AppSettings.Get("EmailUseSsl")),
                ConfigurationManager.AppSettings.Get("EmailUser"),
                ConfigurationManager.AppSettings.Get("EmailPassword")
                );

            //var emailList = mailRepository.GetAllMails("inbox");
            //var emailList = mailRepository.GetMailsBySearch(ConfigurationManager.AppSettings.Get("EmailMailbox"), "jax");
            var emailList = mailRepository.GetUnreadMails("inbox");

            var readImapEmail = emailList as IList <Message> ?? emailList.ToList();

            foreach (Message email in readImapEmail)
            {
                Console.WriteLine("<p>{0}: {1}</p><p>{2}</p>", email.From, email.Subject, email.BodyHtml.Text);
                if (email.Attachments.Count > 0)
                {
                    foreach (MimePart attachment in email.Attachments)
                    {
                        Console.WriteLine("<p>Attachment: {0} {1}</p>", attachment.ContentName, attachment.ContentType.MimeType);
                    }
                }
            }

            return(readImapEmail);
        }
Esempio n. 2
0
 public static void UnreadMailsToConsole(this MailRepository repo)
 {
     foreach (var email in repo.GetUnreadMails())
     {
         Console.WriteLine($"{email.From}: {email.Subject}\r\n{email.BodyText.Text}");
         if (email.Attachments.Count > 0)
         {
             foreach (MimePart attachment in email.Attachments)
             {
                 Console.WriteLine($"Attachment: {attachment.ContentName} {attachment.ContentType.MimeType}");
             }
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Loads the daily CSV from gmail.
        /// </summary>
        public void LoadDailyCSVFromGmail()
        {
            string eodEmailAccount  = ConfigurationManager.AppSettings["EODEmailAccount"];
            string eodEmailPassword = ConfigurationManager.AppSettings["EODEmailPassword"];

            try
            {
                var mailRepository = new MailRepository(
                    "imap.gmail.com",
                    993,
                    true,
                    eodEmailAccount,
                    eodEmailPassword
                    );


                var emailList = mailRepository.GetUnreadMails("inbox");

                foreach (Message email in emailList)
                {
                    if (email.Attachments.Count > 0 && email.Subject == "Daily Historical Data")
                    {
                        foreach (MimePart attachment in email.Attachments)
                        {
                            string result = System.Text.Encoding.UTF8.GetString(attachment.BinaryContent);
                            SaveTickerCSVToLocal(attachment.ContentName, result);
                            //UploadDailyPriceTickerCSVToAzure(attachment.ContentName, result);

                            _auditBLL.Create(new AuditLog
                            {
                                ActionMessage = "Success upload ASX EOD to Azure",
                                ExtraData     = "",
                                ActionType    = ActionType.UploadEODToAzure.ToString(),
                                ActionResult  = ""
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, "Error on uploading EOD csv.");
                LogHelper.Error(_log, ex.ToString());

                throw;
            }
        }