Ejemplo n.º 1
0
        public List<Email> GetMail()
        {
            bool newOnly = Config["GetMailType"].Equals("NEW") ? true : false;

            List<Email> emails = new List<Email>();

            Email email1 = new Email();
            email1.Subject = "Test Body " + DateTime.Now;
            email1.Body = "Test Body " + DateTime.Now;
            email1.From = "*****@*****.**";
            email1.To = "*****@*****.**";

            CurrentMailAccessIndicator = MailAccessIndicator.MailFetched;

            String attachmentFileName = DateTime.Now.ToString("yyyyMMddHHMMss-") + "test.txt";
            emails.Add(email1);
            
            TimeLastChecked = DateTime.Now;
            return emails;
        }
Ejemplo n.º 2
0
        public List<Email> GetMail()
        {
            string getAllMail = Config["GetMailType"].Equals("GETALLMAIL123") ? "ALL" : "UNSEEN";
            MessageCollection remoteEmails;
            List<Email> emails = new List<Email>();
            ImapClient imapClient = new ImapClient(Config["Host_Google"], true, false);
            bool imapConnected = false;
            bool imapLoggedIn = false;

            try
            {
                imapConnected = imapClient.Connect();
                imapLoggedIn = imapClient.Login(Config["User_Google"], Config["Password_Google"]);
                CurrentMailAccessIndicator = MailAccessIndicator.LoggedIn;
            }
            catch (Exception e)
            {
                Logger logger = LogManager.GetCurrentClassLogger();
                logger.Log(LogLevel.Error, "Connection to Google Mail server cannot be established.", e);
            }

            if (imapConnected && imapLoggedIn)
            {
                // Get messages from remote source
                ImapX.Folder InboxFolder = imapClient.Folders.Inbox;
                remoteEmails = InboxFolder.Messages;
                remoteEmails.Download(getAllMail);
                CurrentMailAccessIndicator = MailAccessIndicator.MailChecked;
                
                foreach (Message remoteEmail in remoteEmails)
                {
                    try
                    {
                        Email email = new Email
                        {
                            Date = remoteEmail.Date,
                            From = remoteEmail.From.Address.ToString(),
                            Subject = remoteEmail.Subject,
                            Body = remoteEmail.Body.Text
                        };

                        if (remoteEmail.Attachments.Length > 0)
                        {
                            email.Attachments = new List<Domain.Attachment>();

                            foreach (ImapX.Attachment anAttachment in remoteEmail.Attachments)
                            {
                                anAttachment.Download();
                                string attachmentFileName = DateTime.Now.ToString("yyyyMMddHHMMss.f") + anAttachment.FileName;
                                email.Attachments.Add(
                                    new Domain.Attachment {
                                        FileName = attachmentFileName,
                                        Content = anAttachment.FileData
                                    });
                            }
                        }
                        remoteEmail.Seen = Config["MarkAsSeen"].ToString().Equals("True") ? true : false;
                        emails.Add(email);
                    }
                    catch (Exception e)
                    {
                        Logger logger = LogManager.GetCurrentClassLogger();
                        logger.Log(LogLevel.Error, "Exception occurred when saving emails", e);
                        CurrentMailAccessIndicator = MailAccessIndicator.MailFetchError;

                    }
                    CurrentMailAccessIndicator = MailAccessIndicator.MailFetched;
                }
            }

            imapClient.Dispose();

            TimeLastChecked = DateTime.Now;
            return emails;
        }
 public void LoadMail(Email email)
 {
     throw new NotImplementedException();
 }