public static void Run()
        {
            // ExStart:RemovingMessageFlags
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, Port and SecurityOptions for your client
            client.Host = "imap.gmail.com";
            client.Username = "******";
            client.Password = "******";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                Console.WriteLine("Logged in to the IMAP server");
                // Mark the message as read and Disconnect to the remote IMAP server
                client.RemoveMessageFlags(1, ImapMessageFlags.IsRead);
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            // ExEnd:RemovingMessageFlags
            Console.WriteLine(Environment.NewLine + "Removed message flags from IMAP server.");
        }
        public static void Run()
        {
            // ExStart:RemovingMessageFlags
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, Port and SecurityOptions for your client
            client.Host            = "imap.gmail.com";
            client.Username        = "******";
            client.Password        = "******";
            client.Port            = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                Console.WriteLine("Logged in to the IMAP server");
                // Mark the message as read and Disconnect to the remote IMAP server
                client.RemoveMessageFlags(1, ImapMessageFlags.IsRead);
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            // ExEnd:RemovingMessageFlags
            Console.WriteLine(Environment.NewLine + "Removed message flags from IMAP server.");
        }
Example #3
0
 private void processMessage(uint id, bool retry = true)
 {
     try
     {
         var message = client.GetMessage(id, FetchOptions.TextOnly);
         var data    = message.Body.Replace("\r\n", "\n");
         if (data.Contains("Here is the Steam Guard code you need to login to account "))
         {
             var match = new Regex("Here is the Steam Guard code you need to login to account (.+)\\:\n\n([A-Z0-9]{5})\n").Match(data);
             if (match.Success)
             {
                 if (Program.MailCodeRecieved(match.Groups[1].Value.ToLower(), match.Groups[2].Value))
                 {
                     deleteMail(id);
                 }
                 else
                 {
                     client.AddMessageFlags(id, null, MessageFlag.Flagged);
                     client.RemoveMessageFlags(id, null, MessageFlag.Seen);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error(PREFIX + "Unable to recieve mail " + e + ":");
         Logger.Error(e);
         if (retry)
         {
             Thread.Sleep(1000);
             processMessage(id, false);
         }
     }
 }
Example #4
0
 private void MarkAsRead(ImapClient Client, uint id, bool isRead = true)
 {
     if (isRead)
     {
         Client.AddMessageFlags(id, null, MessageFlag.Seen);
     }
     else
     {
         Client.RemoveMessageFlags(id, null, MessageFlag.Seen);
     }
 }
Example #5
0
        public void CheckForNewReOptEmails(ImapClient _client)
        {
            // Get the ReOptimize first since it always comes in second
            IEnumerable <uint> reOptUid = _client.Search(
                SearchCondition.Subject(Properties.watchReOptSubject)
                .And(SearchCondition.Unseen())
                );

            if (reOptUid.Count() != 0)
            {
                VescoLog.LogEvent("ReOpt email is here.  Grab the ReOpt Email");

                Program.shouldWait = true;
                // Now grab the executed
                IEnumerable <uint> executedUid = _client.Search(
                    SearchCondition.Subject(Properties.watchExSubject)
                    .And(SearchCondition.Unseen())
                    );

                if (executedUid.Count() != 0)
                {
                    VescoLog.LogEvent("Executed email is here.  Grab the Executed Email");

                    // both emails are here, grab the attachments and
                    // drop them in the directory to be processed
                    MailMessage exMailMessage = _client.GetMessage(executedUid.First());
                    Attachment  exAttach      = exMailMessage.Attachments.First();
                    SavePlan(exAttach, Properties.dropExDir);

                    MailMessage reOptMailMessage = _client.GetMessage(reOptUid.First());
                    Attachment  reOptAttachment  = reOptMailMessage.Attachments.First();
                    SavePlan(reOptAttachment, Properties.dropReOptDir);

                    Thread.Sleep(5000); //5 seconds
                    VescoLog.LogEvent("Executed and ReOpt attachments placed in drop directory");
                }
                else
                {
                    // This should never ever happen, but if it does:
                    // revert the ReOpt to unseen, exit out, and try again in 10 minutes
                    VescoLog.LogEvent("ReOpt Found but no Executed.  What up with that?");
                    _client.RemoveMessageFlags(reOptUid.First(), null, MessageFlag.Seen);
                }
            }
            else
            {
                VescoLog.LogEvent("No New ReOpt emails");
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                System.Console.WriteLine("Logged in to the IMAP server");

                // Mark the message as read
                client.RemoveMessageFlags(1, Aspose.Email.Imap.ImapMessageFlags.IsRead);

                //Disconnect to the remote IMAP server
                client.Disconnect();

            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Removed message flags from IMAP server.");
        }
Example #7
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                System.Console.WriteLine("Logged in to the IMAP server");

                // Mark the message as read
                client.RemoveMessageFlags(1, Aspose.Email.Imap.ImapMessageFlags.IsRead);

                //Disconnect to the remote IMAP server
                client.Disconnect();
            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Removed message flags from IMAP server.");
        }
Example #8
0
        public ActionResult MarkEmailAsUnread(uint EmailUDI, string Mailbox)
        {
            if (CheckLogin)
            {
                using (ImapClient Client = QLogin())
                {
                    try
                    {
                        MessageFlag[] RemoveFlags = new MessageFlag[] { MessageFlag.Seen };

                        Client.RemoveMessageFlags(EmailUDI, Mailbox, RemoveFlags);
                        return(OkSuccess());
                    }
                    catch (Exception e)
                    {
                        return(BadRequestFail(e.Message));
                    }
                }
            }
            return(AccessDenied());
        }
    private void ChangeReadStatus(string msgSequenceNumber, string status)
    {
        try
        {
            // initialize imap client
            ImapClient client = new ImapClient();
            client.Host = txtHost.Text;
            client.Port = int.Parse(txtPort.Text);
            client.Username = txtUsername.Text;
            client.Password = Session["Password"].ToString();

            // SSL Settings
            if (chSSL.Checked == true)
            {
                client.EnableSsl = true;
                client.SecurityMode = ImapSslSecurityMode.Implicit;
            }

            // connect to imap server and login
            client.Connect(true);
            client.SelectFolder(ImapFolderInfo.InBox);
            lblMessage.ForeColor = Color.Green;
            lblMessage.Text = "Successfully connected to Imap Mail server.<br><hr>";

            // change the message status
            if (status == "1") // mark as read
                client.AddMessageFlags(int.Parse(msgSequenceNumber), ImapMessageFlags.IsRead);
            else // mark as un-read
                client.RemoveMessageFlags(int.Parse(msgSequenceNumber), ImapMessageFlags.IsRead);

            client.Disconnect();
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
Example #10
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (ImapClient imap = new ImapClient("<ADDRESS> (e.g. imap.gmail.com)"))
        {
            imap.Connect();
            imap.Authenticate("<USERNAME>", "<PASSWORD>");

            // Select INBOX folder.
            imap.SelectInbox();

            // Add "Draft" flag to first message.
            imap.AddMessageFlags(1, ImapMessageFlags.Draft);

            // Get first message flags and display them.
            // Notice the presence of "Draft" flag.
            IList <string> flags = imap.GetMessageFlags(1);
            foreach (string flag in flags)
            {
                Console.WriteLine(flag);
            }

            // Remove "Draft" flag from first message.
            imap.RemoveMessageFlags(1, ImapMessageFlags.Draft);

            Console.WriteLine(new string('-', 10));

            // Again, get first message flags and display them.
            // Notice the absence of "Draft" flag.
            flags = imap.GetMessageFlags(1);
            foreach (string flag in flags)
            {
                Console.WriteLine(flag);
            }
        }
    }
Example #11
0
        public static List <MailMessageContainer> Download(DateTime startPeriod, DateTime finishPeriod, bool makeUnseen = true)
        {
            string hostname = "imap.gmail.com",
                   username = "******", password = "******";

            // The default port for IMAP over SSL is 993.

            using (ImapClient client = new ImapClient(hostname, 993, username, password, AuthMethod.Login, true))
            {
                List <uint>        uids     = client.Search(SearchCondition.SentSince(startPeriod).And(SearchCondition.SentBefore(finishPeriod))).ToList();
                List <MailMessage> messages = client.GetMessages(uids).ToList();

                List <MailMessageContainer> result = new List <MailMessageContainer>();

                //
                for (int i = 0; i < messages.Count(); i++)
                {
                    result.Add(new MailMessageContainer(messages[i], uids[i]));
                    client.RemoveMessageFlags(uids[i], null, new MessageFlag[] { MessageFlag.Seen });
                }
                return(result);
            }
        }
Example #12
0
 public ActionResult SetEmailFlags(uint EmailUDI, EmailFlags EmailFlags, string Mailbox)
 {
     if (CheckLogin)
     {
         using (ImapClient Client = QLogin())
         {
             try
             {
                 List <MessageFlag> AddFlags    = new List <MessageFlag>();
                 List <MessageFlag> RemoveFlags = new List <MessageFlag>();
                 if (EmailFlags.Seen != null)
                 {
                     if (EmailFlags.Seen.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Seen);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Seen);
                     }
                 }
                 if (EmailFlags.Deleted != null)
                 {
                     if (EmailFlags.Deleted.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Deleted);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Deleted);
                     }
                 }
                 if (EmailFlags.Draft != null)
                 {
                     if (EmailFlags.Draft.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Draft);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Draft);
                     }
                 }
                 if (EmailFlags.Recent != null)
                 {
                     if (EmailFlags.Recent.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Recent);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Recent);
                     }
                 }
                 if (EmailFlags.Flagged != null)
                 {
                     if (EmailFlags.Flagged.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Flagged);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Flagged);
                     }
                 }
                 if (EmailFlags.Answered != null)
                 {
                     if (EmailFlags.Answered.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Answered);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Answered);
                     }
                 }
                 Client.AddMessageFlags(EmailUDI, Mailbox, AddFlags.ToArray());
                 Client.RemoveMessageFlags(EmailUDI, Mailbox, RemoveFlags.ToArray());
                 return(OkSuccess());
             }
             catch (Exception e)
             {
                 return(BadRequestFail(e.Message));
             }
         }
     }
     return(AccessDenied());
 }