Exemplo n.º 1
0
 public ImapX.Message GetMailBySubject(string subject)
 {
     ImapX.Message output = null;
     if (!_client.IsConnected)
     {
         if (!_client.Connect())
         {
             return(output);
         }
         if (!_client.Login(_login, _password))
         {
             return(output);
         }
     }
     ImapX.Message[] messages = _client.Folders.Inbox.Search("UNSEEN", ImapX.Enums.MessageFetchMode.Headers); // THIS LINE takes like 5-10 seconds to complete
     foreach (var item in messages)
     {
         if (item.Subject.Contains(subject))
         {
             item.Download(ImapX.Enums.MessageFetchMode.Body);
             output = item;
             break;
         }
     }
     return(output);
 }
Exemplo n.º 2
0
        public static IList <ImapX.Message> Read(string userName, string password, string folder, string search)
        {
            var server = "imap.gmail.com";

            using (var client = new IX.ImapClient(server, true, false)) {
                if (client.Connect())
                {
                    if (client.Login(userName, password))
                    {
                        //var messages = client.Folders.Inbox.Search("UID SEARCH FROM \"[email protected]\"");
                        try {
                            return(client.Folders.Inbox.Search(search));
                        } catch (Exception exc) {
                            throw new ApplicationException(new { userName, folder, server, search } +"", exc);
                        }
                    }
                    else
                    {
                        throw new ApplicationException(new { userName, folder, server, Login = "******" } +"");
                    }
                }
                else
                {
                    throw new ApplicationException(new { userName, folder, server, Connect = "Error" } +"");
                }
            }
        }
Exemplo n.º 3
0
 public MailImapX(string server, string login, string password)
 {
     _server   = server;
     _login    = login;
     _password = password;
     _client   = new ImapX.ImapClient(server, true);
     if (!_client.Connect())
     {
         return;
     }
     if (!_client.Login(_login, _password))
     {
         return;
     }
 }
Exemplo n.º 4
0
 public void Connect(string login, string password)
 {
     if (_client.IsConnected)
     {
         // connection successful
         if (!_client.Login(login, password))
         {
             // login not successful
             throw new AuthenticationException("Invalid login or password");
         }
     }
     else
     {
         // connection not successful
         throw new ConnectionException("Connection is lost");
     }
 }