public static void Run()
        {
            //ExStart:DeleteSingleMessage
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-35227 - " + Guid.NewGuid(), "EMAILNET-35227 Add ability in ImapClient to delete message");
                    string emailId = client.AppendMessage(message);

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Select the inbox folder and Delete message
                    client.SelectFolder(ImapFolderInfo.InBox);
                    client.DeleteMessage(emailId);
                    client.CommitDeletes();
                }
                finally
                {

                }
            }
            //ExEnd:DeleteSingleMessage
        }
Beispiel #2
0
        public static void Run()
        {
            //ExStart:DeleteSingleMessage
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-35227 - " + Guid.NewGuid(), "EMAILNET-35227 Add ability in ImapClient to delete message");
                    string      emailId = client.AppendMessage(message);

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Select the inbox folder and Delete message
                    client.SelectFolder(ImapFolderInfo.InBox);
                    client.DeleteMessage(emailId);
                    client.CommitDeletes();
                }
                finally
                {
                }
            }
            //ExEnd:DeleteSingleMessage
        }
        public void EmptyInbox()
        {
            // delete specific emails
            using (ImapClient Client = new ImapClient("imap.gmail.com", 993, "*****@*****.**", "aq1sw2de3fr4", AuthMethod.Login, true))
            {
                IEnumerable <uint> uids = Client.Search(SearchCondition.All());

                foreach (uint uid in uids)
                {
                    MailMessage msg    = Client.GetMessage(uid, FetchOptions.Normal);
                    bool        delete = false;

                    // process the message here
                    if (msg.Subject.Equals("subject"))
                    {
                        Console.WriteLine("subject message deleting...");
                        delete = true;
                    }

                    if (delete)
                    {
                        Client.DeleteMessage(uid);
                    }
                }
            }
        }
Beispiel #4
0
 private static void DeleteMessage(string uid)
 {
     using (var imap = new ImapClient(Host, UserName, Password, ImapClient.AuthMethods.Login, Port, false))
     {
         imap.DeleteMessage(uid);
     }
 }
Beispiel #5
0
        public void DeleteAllMessages()
        {
            DashBoardMailBoxJob model = new DashBoardMailBoxJob();

            model.Inbox = new List <MailMessege>();
            string accountType = "gmail";

            try
            {
                EmailConfiguration email = new EmailConfiguration();
                switch (accountType)
                {
                case "Gmail":
                    // type your popserver
                    email.POPServer = "imap.gmail.com";
                    break;

                case "Outlook":
                    // type your popserver
                    email.POPServer = "outlook.office365.com";
                    break;
                }
                email.POPUsername  = UserName; // type your username credential
                email.POPpassword  = Password; // type your password credential
                email.IncomingPort = "993";
                email.IsPOPssl     = true;


                ImapClient ic = new ImapClient(email.POPServer, email.POPUsername, email.POPpassword, AuthMethods.Login, Convert.ToInt32(email.IncomingPort), (bool)email.IsPOPssl);
                // Select a mailbox. Case-insensitive
                ic.SelectMailbox("INBOX");
                int i        = 1;
                int msgcount = ic.GetMessageCount("INBOX");
                int end      = msgcount - 1;
                int start    = msgcount - msgcount;
                // Note that you must specify that headersonly = false
                // when using GetMesssages().
                MailMessage[] mm = ic.GetMessages(start, end, false);
                // var messages = ic.GetMessages(start, end, true);
                foreach (var it1 in mm)
                {
                    ic.DeleteMessage(it1);
                }


                ic.Dispose();
            }

            catch (Exception e)
            {
                model.mess = "Error occurred retrieving mail. " + e.Message;
            }
            finally
            {
            }
            //return model.Inbox;
        }
        public bool Delete(uint uid, string mailbox)
        {
            if (uid <= 0)
            {
                throw new ArgumentOutOfRangeException("uid");
            }

            _client.DeleteMessage(uid, mailbox);

            return(true);
        }
Beispiel #7
0
 private void deleteMail(uint id)
 {
     try
     {
         client.DeleteMessage(id);
         client.Expunge();
     }
     catch (Exception e)
     {
         Logger.Error(PREFIX + "Unable to delete mail " + e + ":");
         Logger.Error(e);
     }
 }
Beispiel #8
0
        static void connection()
        {
            string path   = "../../docs";
            string server = "imap.gmail.com";
            string email  = "";
            string pw     = "";

            try
            {
                using (ImapClient ic = new ImapClient(server, email, pw, AuthMethods.Login, 993, true))
                {
                    ic.SelectMailbox("inbox");
                    Console.WriteLine("running");
                    int x = 0;
                    Lazy <AE.Net.Mail.MailMessage>[] messages = ic.SearchMessages(SearchCondition.Undeleted(), false);

                    foreach (Lazy <AE.Net.Mail.MailMessage> msg in messages)
                    {
                        AE.Net.Mail.MailMessage m = msg.Value;
                        string sender             = m.From.Address;
                        string FileName           = string.Empty;

                        if (sender == "*****@*****.**")
                        {
                            FileName = "../../docs/boardingpass";
                            Directory.CreateDirectory(path);
                            foreach (AE.Net.Mail.Attachment attachment in m.Attachments)
                            {
                                if (attachment.Filename.Contains("invoice") == false)
                                {
                                    x++;
                                    FileName = FileName + x;
                                    attachment.Save(FileName + Path.GetExtension(attachment.Filename));
                                    Pdf2text(FileName);
                                }
                            }

                            sendemail(cl);
                            Directory.Delete(path, true);
                            ic.DeleteMessage(m);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }
        public void getUnreadEmails()
        {
            InsuredTravelingEntity entities = new InsuredTravelingEntity();
            string n = "[notification]";

            using (ImapClient client = new ImapClient("imap.zoho.com", 993,
                                                      "*****@*****.**", "Enter4Sy", AuthMethod.Login, true))
            {
                IEnumerable <uint> uids = client.Search(SearchCondition.Unseen());

                foreach (uint uid in uids)
                {
                    MailMessage message = client.GetMessage(uid);
                    news_all    news    = entities.news_all.Create();;
                    news.Title            = message.Subject.Trim();
                    news.Content          = message.Body.Trim();
                    news.DataCreated      = (DateTime)message.Date();
                    news.InsuranceCompany = "Eurolink";
                    Random r = new Random();
                    //news.ID = r.Next(10000, 99999);
                    if (message.Subject.ToLower().StartsWith(n))
                    {
                        news.isNotification = true;
                    }
                    else
                    {
                        news.isNotification = false;
                    }

                    entities.news_all.Add(news);

                    client.MoveMessage(uid, "SeenNews");
                    client.DeleteMessage(uid, "Inbox");
                }

                client.Expunge("Inbox");
                client.Dispose();

                if (uids.Count() != 0)
                {
                    entities.SaveChanges();
                }
            }
        }
Beispiel #10
0
 private void _timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     _timer.Stop();
     using (var client = new ImapClient(_imapServer, _userName, _password, AuthMethods.Login, _imapPort, _imapUseSsl))
     {
         int msgCount = client.GetMessageCount();
         var msg      = client.GetMessages(msgCount - 10, msgCount)
                        .FirstOrDefault(m => m.Subject.ToLower().Contains("pj restart me") && m.Date >= _lastCheck.AddMinutes(-2));
         if (msg != null)
         {
             sendEmail("PJ RESTARTING", "PJ RESTARTING");
             try
             {
                 client.DeleteMessage(msg);
             }
             catch { }
             Process.Start("shutdown", "/r /f");
         }
     }
     _lastCheck = DateTime.Now;
     _timer.Start();
 }
Beispiel #11
0
        bool handleMessage(ImapClient client, uint uid, MailMessage msg)
        {
            client.AddMessageFlags(uid, null, MessageFlag.Seen);

            foreach (var file in msg.Attachments)
            {
                string solution = file.toString();

                string header          = solution;
                int    firstLineLength = solution.IndexOfAny(Util.LineEndings);
                if (firstLineLength > 0)
                {
                    header = solution.Substring(0, firstLineLength);
                }

                DateTime now = DateTime.Now;

                // TODO[szx][0]: handle deserialization failure.
                Submission submission = Util.Json.fromJsonString <Submission>(header);
                submission.email = msg.From.Address;
                submission.date  = Util.friendlyDateTime(now);

                Problem problem;
                if (!page.rank.problems.TryGetValue(submission.problem, out problem))
                {
                    continue;
                }
                Instance instance;
                if (!problem.instances.TryGetValue(submission.instance, out instance))
                {
                    continue;
                }

                string dir = CommonCfg.ArchiveDir + submission.problem + "/";
                Directory.CreateDirectory(dir);
                string filePath = dir + Util.compactDateTime(now) + "-" + submission.instance;
                File.WriteAllText(filePath, solution);

                if (page.checkers.TryGetValue(problem.checkerPath, out Checker.Check check))
                {
                    submission.obj = check(solution);
                }
                else if (File.Exists(problem.checkerPath))
                {
                    string obj = Util.runRead(problem.checkerPath, dir + submission.instance + " " + filePath);
                    if (!double.TryParse(obj, out submission.obj))
                    {
                        File.Delete(filePath); continue;
                    }
                }
                else
                {
                    submission.obj = 0;
                }

                if (submission.obj <= 0)
                {
                    continue;
                }                                      // infeasible or trivial solution.

                Util.run("git", "add " + filePath);

                instance.results.Add(new Result {
                    path = filePath, header = submission
                });

                if (instance.results.Count > CommonCfg.MaxResultsCountPerInstance)
                {
                    instance.results.Remove(problem.minimize ? instance.results.Max : instance.results.Min);
                }
            }
            client.DeleteMessage(uid);

            return(true);
        }
Beispiel #12
0
 public static void deleteMail(AE.Net.Mail.MailMessage m)
 {
     mImapClient.DeleteMessage(m);
 }
Beispiel #13
0
 private void deleteMail(uint id)
 {
     client.DeleteMessage(id);
     client.Expunge();
 }