示例#1
0
        private void login_Click(object sender, RoutedEventArgs e)
        {
            if (NameMail.Text != "" && textPassword.Password != "")
            {
                info_Send.Mail    = NameMail.Text;
                info_Send.pasword = textPassword.Password;
                if (Gmail.IsChecked == true)
                {
                    info_Send.emailClient   = ConfigurationManager.AppSettings["gmail_server"];
                    info_Send.port          = int.Parse(ConfigurationManager.AppSettings["gmail_port"]);
                    info_Send.portmp        = int.Parse(ConfigurationManager.AppSettings["gmail_portMp"]);
                    info_Send.emailClientMp = ConfigurationManager.AppSettings["gmail_serverMp"];
                }
                else if (ukrnet.IsChecked == true)
                {
                    info_Send.emailClient   = ConfigurationManager.AppSettings["ukr_server"];
                    info_Send.port          = int.Parse(ConfigurationManager.AppSettings["ukr_port"]);
                    info_Send.portmp        = int.Parse(ConfigurationManager.AppSettings[" ukr_portMp"]);
                    info_Send.emailClientMp = ConfigurationManager.AppSettings["ukr_serverMp"];
                }
                Console.WriteLine("Login secsesful");
                login.IsEnabled = false;



                MailServer server = new MailServer(
                    info_Send.emailClientMp,
                    info_Send.Mail,
                    info_Send.pasword,
                    ServerProtocol.Imap4)
                {
                    SSLConnection = true,
                    Port          = info_Send.portmp
                };

                client = new MailClient("TryIt"); // trial version

                try
                {
                    client.Connect(server);

                    foreach (var f in client.GetFolders())
                    {
                        folderText.Items.Add(f.Name);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
示例#2
0
 private void folderText_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     bodymessegeText.Items.Clear();
     foreach (var f in client.GetFolders())
     {
         if (f.Name == folderText.SelectedItem.ToString())
         {
             foreach (var subF in f.SubFolders)
             {
                 bodymessegeText.Items.Add("\t" + subF.Name);
             }
         }
     }
 }
 void getFoldersDisplayed()
 {
     try
     {
         Imap4Folder[] allFolders = mailClient.GetFolders();
         cmbFolders.Items.Clear();
         foreach (Imap4Folder imap4f in allFolders)
         {
             cmbFolders.Items.Add(new Imap4FolderItem(imap4f));
         }
         foreach (Imap4FolderItem imap4FolderItem in cmbFolders.Items)
         {
             if (imap4FolderItem.imap4Folder.Name == "INBOX")
             {
                 cmbFolders.SelectedItem = imap4FolderItem;
             }
         }
     }
     catch (Exception ex)
     {
         Text = "rozłączono";
     }
 }
示例#4
0
        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            FoldersList.Items.Clear();
            mServer = new MailServer(
                "imap.gmail.com",
                emailTB.Text,
                passwordTB.Text,
                EAGetMail.ServerProtocol.Imap4)
            {
                SSLConnection = true, Port = 993
            };
            smtpServer = new SmtpServer("smtp.gmail.com")
            {
                Port        = 465,
                ConnectType = SmtpConnectType.ConnectSSLAuto,
                User        = emailTB.Text,
                Password    = passwordTB.Text
            };
            mClient = new MailClient("TryIt");
            try
            {
                mClient.Connect(mServer);


                foreach (var f in mClient.GetFolders())
                {
                    foreach (var subF in f.SubFolders)
                    {
                        FoldersList.Items.Add(subF.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#5
0
        static void parseEmail()
        {
            try
            {
                string localInbox = "mails";

                // Create local folder to store email containing task-order details
                if (!Directory.Exists(localInbox))
                {
                    Directory.CreateDirectory(localInbox);
                }

                //MailServer localServer = new MailServer("pop-mail.outlook.com", "*****@*****.**", "Winter2021!", ServerProtocol.Pop3);
                MailServer localServer = new MailServer("imap-mail.outlook.com", "*****@*****.**", "Winter2021!", ServerProtocol.Imap4);


                // Enable SSL/TLS Connection
                localServer.SSLConnection = true;
                localServer.Port          = 993;

                MailClient localClient = new MailClient("TryIt");
                localClient.Connect(localServer);

                Imap4Folder folder = FindFolder("NITAAC", localClient.GetFolders());
                if (folder == null)
                {
                    throw new Exception("Folder not found!");
                }

                localClient.SelectFolder(folder);
                System.Diagnostics.Debug.WriteLine("Retrieving Email list...");

                //localClient.GetMailInfosOption = GetMailInfosOptionType.GetCategories;
                //localClient.GetMailInfosParam.Reset();
                //localClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.NewOnly;

                MailInfo[] infos = localClient.GetMailInfos();
                //System.Diagnostics.Debug.WriteLine("\n Total {0} email(s)", infos.Length);

                //Mail firstClient = localClient.GetMail(infos[0]);
                //DateTime firstDate = firstClient.ReceivedDate;
                string        bodyText = "";
                SqlConnection con      = new SqlConnection(connectionstring);
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                SqlDataAdapter adapter  = new SqlDataAdapter();
                string         delquery = "delete from task_order";
                SqlCommand     delcmd   = new SqlCommand(delquery, con);
                delcmd.ExecuteNonQuery();

                for (int i = 0; i < infos.Length; i++)
                {
                    MailInfo info = infos[i];

                    // Recieve Mail from POP3 server
                    Mail localmail = localClient.GetMail(info);
                    System.Diagnostics.Debug.WriteLine("Subject: {0}\r\n", localmail.Subject);
                    bodyText = localmail.TextBody;

                    localmail.DecodeTNEF();

                    Attachment[] atts = localmail.Attachments;

                    /*if (localmail.Subject.Contains("New Task Order") && DateTime.Compare(localmail.ReceivedDate, firstDate) > 0)
                     * {
                     *  //System.Diagnostics.Debug.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",info.Index, info.Size, info.UIDL);
                     *  //System.Diagnostics.Debug.WriteLine("From: {0}", localmail.From.ToString());
                     *  //System.Diagnostics.Debug.WriteLine("Subject: {0}", localmail.Subject);
                     *  bodyText = localmail.TextBody;
                     *
                     * }*/
                    loadInDB(bodyText, atts);
                    //System.Diagnostics.Debug.WriteLine("From: {0}", localmail.From.ToString());
                    //System.Diagnostics.Debug.WriteLine("Subject: {0}\r\n", localmail.Subject);

                    //string filename = generateFileName(i + 1);
                    //string path = string.Format("{0}\\{1}", localInbox, filename);

                    // Save email to local disk
                    //localmail.SaveAs(path, true);
                }

                //System.Diagnostics.Debug.WriteLine("Contents: {0}", bodyText);

                //System.Diagnostics.Debug.WriteLine("Task Order Name:"+taskOrderName);

                localClient.Quit();
                System.Diagnostics.Debug.WriteLine("Completed!");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }