Пример #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();
                }
            }
        }
Пример #2
0
        private static string GetEmail(string v1, string v2)
        {
            ImapClient client = new ImapClient("imap.openmailbox.org", v1, v2, AuthMethods.Login, 993, true);

            client.SelectMailbox("INBOX");

            MailMessage[] listemail = client.GetMessages(0,20);
            MailMessage email = listemail[12];
            if(String.IsNullOrEmpty(email.Body))
            {
                string body = client.GetMessage(email.Uid).Subject;
                client.Dispose();
                return body;
            }
            client.Dispose();
            return email.Subject;
        }
        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;

        }
 // This is where all the magic happens.
 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     StatusBarText = "Connecting to server...";
     try
     {
         ImapClient ic = new ImapClient(ServerName, Username, Password, AuthMethods.Login, 993, true);
         ic.SelectMailbox("INBOX");
         Lazy<MailMessage>[] messages = ic.SearchMessages(SearchCondition.Unseen(), true, false);
         display.printNumber(messages.Length);
         StatusBarText = "Number of unread messages: " + messages.Length;
         ic.Disconnect();
         ic.Dispose();
     }
     catch (Exception ex)
     {
         StatusBarText = ex.Message;
         StopRunning();
     }
 }
Пример #5
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();

    }
Пример #6
0
        //Metode for å hente inn mail
        public static void mottaMail()
        {
            ImapClient ic = null;
            try
            {
                //Lager nytt objekt av klassen ImapClient
                ic = new ImapClient(host, sendMail.email, sendMail.password,
                     ImapClient.AuthMethods.Login, port, secure);
                ic.SelectMailbox("INBOX");

                //Array som henter inn alle mail i innboksen
                MailMessage[] mail = ic.GetMessages(0, 1, false, true);

                //If-setning som sjekker om det er mail i innboksen
                if (mail.Length != 0)
                {
                    //Tre variabler som henter ut informasjon fra den siste motatte mailen
                    from = mail[mail.Length - 1].From.Address;

                    //Løkke med if-setning som sjekker om mailen er lagt til i databasen
                    foreach (DataRow dtRow in GUI_FORM.dtEmails.Rows)
                    {
                        if (from == dtRow["Adresser"].ToString())
                        {
                            subject = mail[mail.Length - 1].Subject;
                            body = mail[mail.Length - 1].Body;
                        }

                    }
                    //Løkke som sletter alle mail etter den har hentet inn den siste
                    foreach (MailMessage m in mail) ic.DeleteMessage(m);

                }
                warningSentMotta = false;
            }
            catch (Exception ex)
            {
                if (warningSentMotta == false)
                {
                    warningSentMotta = true; //Unngår spam
                    Logger.Error(ex, module);
                }
            }
            finally
            {
                if (ic != null) ic.Dispose();
            }
        }
Пример #7
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 { }
        }
Пример #8
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;
            }
        }
Пример #9
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 { }
 }