Esempio n. 1
1
        private void CheckEmail()
        {
            ImapClient client = null;

            try
            {
                client = new ImapClient(MailServer, MailAccount, Password, ImapClient.AuthMethods.Login, Port, true);

                client.SelectMailbox(MailboxName);
                int messageCount = client.GetMessageCount();
                if (messageCount > 0)
                {
                    var messages = client.GetMessages(0, messageCount, false);

                    foreach (MailMessage message in messages.OrderBy(m=>m.Date))
                    {

                        ProcessAndFireEvent(message);

                        client.MoveMessage(message.Uid, ProcessedFolderName);
                    }
                }
            }
            catch (Exception e)
            {
                // :(
            }
            finally
            {
                if (client != null)
                {
                    client.Dispose();
                }
            }
        }
 private PlugResponse GetLastMailSubject()
 {
     List<MailMessage> msgs = null;
     using (ImapClient client = new ImapClient(HOST, LOGIN, PWD, AuthMethods.Login, PORT, true))
     {
         DateTime dt = DateTime.Now.AddHours(-1);
         msgs = client.GetMessages(client.GetMessageCount() - 5, client.GetMessageCount(), false).ToList();
     }
     MailMessage oneMessage = msgs.MaxBy(mess => mess.Uid);
     RESPONSE.Params.Add("UID", oneMessage.Uid);
     RESPONSE.WaitForChainedAction = true;
     RESPONSE.NextChainedAction = "GetBodyMessage";
     RESPONSE.ChainedQuestion = "Souhaitez vous une lecture de l'email ?";
     RESPONSE.Response = oneMessage.Subject;
     return RESPONSE;
 }
        static void Main(string[] args)
        {
            ImapClient client = new ImapClient("imap.gmail.com", "*****@*****.**", "6ot04obb", AuthMethods.Login, 993, true);
            DateTime dt = DateTime.Now.AddHours(-1);
            List<MailMessage> msgs = client.GetMessages(client.GetMessageCount() -5, client.GetMessageCount(), false).ToList();

            MailMessage oneMessage = msgs.MaxBy(mess => mess.Uid);
            var message = msgs.First();
            Console.ReadLine();
        }
Esempio n. 4
0
        private static MailMessage[] GetEmails()
        {
            List<MailMessage> response = new List<MailMessage>();

            using (var imap = new ImapClient(Host, UserName, Password, ImapClient.AuthMethods.Login, Port, false))
            {
                imap.SelectMailbox("INBOX");

                // Get message count
                var messageCount = imap.GetMessageCount();

                if (messageCount == 0)
                    return response.ToArray();

                var msgs = imap.GetMessages(0, (messageCount - 1)).ToArray();

                foreach (MailMessage msg in msgs)
                {
                    var flags = msg.Flags.ToString();
                    if (!flags.Contains("Deleted"))
                        response.Add(msg);
                }
            }

            return response.ToArray();
        }
        public static GAAutentication Autenticate(string _client_id, string _client_secret)
        {
            GAAutentication result = new GAAutentication();
           
            try
            {
               UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = _client_id, ClientSecret = _client_secret },
                                                                         new[] {"https://mail.google.com/ email" },
                                                                         "Lindau",
                                                                         CancellationToken.None,
                                                                         new FileDataStore("Analytics.Auth.Store")).Result;
            }
            catch (Exception ex)
            {

                int i = 1;
            }

            if (result.credential != null)
            {

                result.service = new PlusService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = result.credential,
                    ApplicationName = "Google mail",
                });

        
                Google.Apis.Plus.v1.Data.Person me = result.service.People.Get("me").Execute();

                Google.Apis.Plus.v1.Data.Person.EmailsData myAccountEmail =  me.Emails.Where(a => a.Type == "account").FirstOrDefault();

                // Connect to the IMAP server. The 'true' parameter specifies to use SSL
                // which is important (for Gmail at least)
                ImapClient ic = new ImapClient("imap.gmail.com", myAccountEmail.Value, result.credential.Token.AccessToken,
                                ImapClient.AuthMethods.SaslOAuth, 993, true);
                // Select a mailbox. Case-insensitive
                ic.SelectMailbox("INBOX");
                Console.WriteLine(ic.GetMessageCount());
                // Get the first *11* messages. 0 is the first message;
                // and it also includes the 10th message, which is really the eleventh ;)
                // MailMessage represents, well, a message in your mailbox
                MailMessage[] mm = ic.GetMessages(0, 10);
                foreach (MailMessage m in mm)
                {
                    Console.WriteLine(m.Subject + " " + m.Date.ToString());
                }
                // Probably wiser to use a using statement
                ic.Dispose();
            }
            return result;

        }
Esempio n. 6
0
    public void TestMethod1()
    {
      Pop3Client pc = new Pop3Client("mail.jacobgudbjerg.dk", "*****@*****.**", "jacobgud");

      var pi = pc.GetMessageCount();

//      var mes = pc.GetMessage(0);

      //mes.Attachments.First().Save(@"c:\temp\foto.jpg");

      pc.Dispose();

      ImapClient IC = new ImapClient("imap.gmail.com", "*****@*****.**", "", ImapClient.AuthMethods.Login,993,true);
      var i = IC.GetMessageCount("Inbox");

      var mes = IC.GetMessage(IC.GetMessageCount()-1);

      mes.Attachments.First().Save(@"c:\temp\foto.jpg");
      IC.Dispose();

    }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //MailScrap mailScrap = new MailScrap();

            //mailScrap.InitializeConnection("imap.gmail.com", 993);

            //mailScrap.AuthenticateUser("*****@*****.**", "naresh14GMAIL");

            Console.WriteLine("Enter your Gmail Address:");
            var addr = Console.ReadLine();

            Console.WriteLine("Enter your Gmail Password(Trust me it is safe):");
            var pwd = Console.ReadLine();

            Console.WriteLine("Folder Path");
            var path = Console.ReadLine();

            using (var imap = new AE.Net.Mail.ImapClient("imap.gmail.com", addr, pwd, AuthMethods.Login, 993, true))
            {
                //var mb = imap.ListMailboxes("", "*");
                imap.SelectMailbox("[Gmail]/Spam");


                var count = imap.GetMessageCount();

                Console.WriteLine($"Spam Count: {count}");

                var msgs = imap.GetMessages(0, count - 1, false);
                int i    = 0;
                foreach (var msg in msgs)
                {
                    File.WriteAllText($@"{path}\Spam{i}.txt", msg.Body);
                    i++;
                }

                //var msgs = imap.SearchMessages(
                //  SearchCondition.Undeleted().And(
                //    SearchCondition.From("david"),
                //    SearchCondition.SentSince(new DateTime(2000, 1, 1))
                //  ).Or(SearchCondition.To("andy"))
                //);

                //Flags.
            }
            Console.WriteLine("You have been Hacked ;P");
            Console.WriteLine("Press any key.");
            Console.ReadLine();
        }
Esempio n. 8
0
        /// <summary>
        /// Function Name : ParseNewEmail
        /// Input Parameters : none  
        /// Input Parameter Type : none
        /// Description:This method is going to record the event when an email is received to the Test email. It uses ImapClient which is available in AE.Net.Mail Nuget package.
        /// ImapClient has inbuilt properties to extract subject, body, sender information details from a newly received email
        /// </summary>
        /// <returns>
        /// Return Parameter : emailJson 
        /// Return Parameter Type : string
        /// </returns>

        public string ParseNewEmail()
        {
            // Connect to the IMAP server. The 'true' parameter specifies to use SSL, which is important (for Gmail at least)
            ImapClient imapClient = new ImapClient(ConfigurationManager.AppSettings["ImapServer"], ConfigurationManager.AppSettings["UserId"], ConfigurationManager.AppSettings["Password"], AuthMethods.Login, 993, true);
            var userName = ConfigurationManager.AppSettings["UserID"];
          //  ImapClient imapClient = new ImapClient(ConfigurationManager.AppSettings["ImapServer"], "*****@*****.**", "7Ywy7N[S", AuthMethods.Login, 993, true);
            // Select a mailbox. Case-insensitive
            imapClient.SelectMailbox("INBOX");
            string emailJson="";           
            Console.WriteLine(imapClient.GetMessageCount());

            imapClient.NewMessage += (sender, e) =>
            {
                var msg = imapClient.GetMessage(e.MessageCount - 1);                             
                string result = "";
                UpdatePackage up = new UpdatePackage();               
                List<string> li = new List<string>();
                up.Subject = msg.Subject;
                up.Body = msg.Body;
                up.Updates = ParseBody(msg.Body);
                li = ParseSubject(msg.Subject);
                up.ProjectName = li[li.Count - 1];
                up.Updates.Add("PhaseId", li[1]);
                up.Updates.Add("VerticalId", li[2]);
                emailJson = JsonConvert.SerializeObject(up);
               
                using (var client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                   // result = client.UploadString("https://localhost:44300/ProjectUpdate/Update", "Post", emailJson);
                    result = client.UploadString("http://costcodevops.azurewebsites.net/ProjectUpdate/Update", "Post", emailJson);
                    Console.WriteLine(result);
                }

            };
           return emailJson;           
        }
Esempio n. 9
0
 private static MailMessage GetLastMessageFromInBox(string testAccountName,string testAccountPassword,string folderName="INBOX")
 {
     // Connect to the IMAP server. 
     MailMessage message = null;
     Console.WriteLine(EnvironmentSettings.TestAccountName);
     Console.WriteLine(EnvironmentSettings.TestAccountPassword);
     using (ImapClient ic = new ImapClient(EnvironmentSettings.TestEmailServerHost, EnvironmentSettings.TestAccountName, EnvironmentSettings.TestAccountPassword,
                     ImapClient.AuthMethods.Login, 993, true))
     {
         // Select folder and get the last mail.
         ic.SelectMailbox(folderName);
         message= ic.GetMessage(ic.GetMessageCount() - 1);
                        
     }
     return message;
 }
Esempio n. 10
0
        private void tmr_email_Tick(object sender, EventArgs e)
        {
            try
            {
                ImapClient ic = new ImapClient("imap.gmail.com", emailuser, emailpass,
                                    ImapClient.AuthMethods.Login, 993, true);
                ic.SelectMailbox("INBOX");
                MailMessage[] mm = ic.GetMessages(0, ic.GetMessageCount());
                if (mm[ic.GetMessageCount() - 1].Subject != latestemail)
                {
                    latestemail = mm[ic.GetMessageCount() - 1].Subject;
                    emailstrip.DropDownItems.Add(latestemail);
                    Notification frmOut = new Notification();
                    frmOut.Set_Text(mm[ic.GetMessageCount() - 1].Subject);
                    frmOut.Show();
                }

                ic.Dispose();
            }
            catch { }
        }
Esempio n. 11
0
        private void rSSEmailToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rSSEmailToolStripMenuItem.Checked == false)
            {
                try
                {
                    emailuser = txt_emailuser.Text;
                    emailpass = txt_emailpass.Text;
                    ImapClient ic = new ImapClient("imap.gmail.com", emailuser, emailpass,
                                    ImapClient.AuthMethods.Login, 993, true);
                    ic.SelectMailbox("INBOX");
                    MailMessage[] mm = ic.GetMessages(0, ic.GetMessageCount());
                    latestemail = mm[ic.GetMessageCount() - 1].Subject;
                    ic.Dispose();

                    try
                    {
                        switch (cmb_emailtime.SelectedItem.ToString())
                        {
                            case "3 Seconds":
                                tmr_email.Interval = 3000;
                                tmr_email.Enabled = true;
                                break;

                            case "5 Seconds":
                                tmr_email.Interval = 5000;
                                tmr_email.Enabled = true;
                                break;

                            case "10 Seconds":
                                tmr_email.Interval = 10000;
                                tmr_email.Enabled = true;
                                break;

                            case "30 Seconds":
                                tmr_email.Interval = 30000;
                                tmr_email.Enabled = true;
                                break;

                            case "1 Minute":
                                tmr_email.Interval = 60000;
                                tmr_email.Enabled = true;
                                break;

                            case "5 Minutes":
                                tmr_email.Interval = 300000;
                                tmr_email.Enabled = true;
                                break;

                            case "10 Minutes":
                                tmr_email.Interval = 600000;
                                tmr_email.Enabled = true;
                                break;

                            case "30 Minutes":
                                tmr_email.Interval = 1800000;
                                tmr_email.Enabled = true;
                                break;

                            case "1 Hour":
                                tmr_email.Interval = 3600000;
                                tmr_email.Enabled = true;
                                break;

                            default:
                                tmr_email.Interval = 10000;
                                tmr_email.Enabled = true;
                                break;
                        }
                    }
                    catch
                    {
                        tmr_email.Interval = 10000;
                        tmr_email.Enabled = true;
                    }

                    rSSEmailToolStripMenuItem.Checked = true;
                }
                catch { }
            }
            else
            {
                tmr_email.Enabled = false;
                rSSEmailToolStripMenuItem.Checked = false;
            }
        }
Esempio n. 12
0
 private void currentEmailNotificationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         emailuser = txt_emailuser.Text;
         emailpass = txt_emailpass.Text;
         emailstrip.DropDownItems.Clear();
         ImapClient ic = new ImapClient("imap.gmail.com", emailuser, emailpass,
                         ImapClient.AuthMethods.Login, 993, true);
         ic.SelectMailbox("INBOX");
         MailMessage[] mm = ic.GetMessages(0, ic.GetMessageCount());
         foreach (MailMessage m in mm)
         {
             emailstrip.DropDownItems.Add(m.Subject);
         }
         ic.Dispose();
     }
     catch { }
 }