static void Main(string[] args)
        {
            using (Imap imap = new Imap())
            {
                imap.ConnectSSL("imap.gmail.com");
                imap.UseBestLogin("*****@*****.**", "password for Gmail apps");
                // Recognize Trash folder
                List <FolderInfo> folders = imap.GetFolders();

                CommonFolders common = new CommonFolders(folders);

                FolderInfo trash = common.Trash;
                // Find all emails we want to delete
                imap.Select(trash);
                List <long> uidList = imap.Search(Flag.All);
                foreach (long uid in uidList)
                {
                    imap.DeleteMessageByUID(uid);
                    Console.WriteLine("{0} deleted", uid);
                }
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
                imap.Close();
            }
        }
Exemplo n.º 2
0
        public void SendMessage()
        {
            try
            {
                XElement element = XElement.Load("MailSettings.xml");

                MailBuilder builder = new MailBuilder();
                //builder.Subject = String.Format("{0} - {1}", themeTxb.Text, SendMail.MailSettings.SenderName);
                builder.Subject = themeTxb.Text + " - " + element.Element("GeneralInformation").Element("senderName").Value;
                //builder.Subject = themeTxb.Text + " - " + SendMail.MailSettings.SenderName;
                builder.From.Add(new MailBox(element.Element("GeneralInformation").Element("email").Value, element.Element("GeneralInformation").Element("email").Value));
                //builder.From.Add(new MailBox(SendMail.MailSettings.Email));
                builder.To.Add(new MailBox(whomTxb.Text));
                builder.Text = contentTxb.Text;
                if (attachBtnFlag == true)
                {
                    foreach (var i in pathFileName)
                    {
                        builder.AddAttachment(i);
                    }
                }

                IMail email = builder.Create();

                using (Smtp smtp = new Smtp())
                {
                    smtp.ConnectSSL(element.Element("SendingMail").Element("sendingMail").Value);
                    //smtp.ConnectSSL(SendMail.MailSettings.SendingMail);
                    smtp.Configuration.EnableChunking = true;
                    smtp.UseBestLogin(element.Element("SendingMail").Element("sendingLogin").Value, element.Element("SendingMail").Element("sendingPassword").Value);
                    //smtp.UseBestLogin(SendMail.MailSettings.SendingLogin, SendMail.MailSettings.SendingPassword);
                    smtp.SendMessage(email);
                    MessageBox.Show("Електронний лист успішно надіслано!");
                }

                using (Imap imap = new Imap())
                {
                    imap.ConnectSSL(element.Element("ReceivingMail").Element("receivingMail").Value);
                    //imap.ConnectSSL(SendMail.MailSettings.ReceivingMail);
                    imap.UseBestLogin(element.Element("ReceivingMail").Element("receivingLogin").Value, element.Element("ReceivingMail").Element("receivingPassword").Value);
                    //imap.UseBestLogin(SendMail.MailSettings.ReceivingLogin, SendMail.MailSettings.ReceivingPassword);

                    CommonFolders folders = new CommonFolders(imap.GetFolders());
                    imap.UploadMessage(folders.Sent, email);

                    imap.Close();
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (Imap imap = new Imap())
            {
                imap.ConnectSSL("imap." + client);
                imap.Login(login, password);

                CommonFolders folders = new CommonFolders(imap.GetFolders());
                imap.Select(folders.Trash);

                MailBuilder builder = new MailBuilder();
                counter = 0;
                foreach (long uid in imap.Search(Flag.All))
                {
                    IMail  email = builder.CreateFromEml(imap.GetMessageByUID(uid));
                    string body  = email.Subject + " " + email.Text;

                    canonbody = new List <string>();
                    canonbody = myCanonize.canonize(body);


                    for (int i = 0; i < canonlist.Count; i++)
                    {
                        for (int j = 0; j < canonbody.Count; j++)
                        {
                            if (myCanonize.LevenshteinDistance(canonlist[i], canonbody[j]) < 3)
                            {
                                values.Add(percentSpam.ElementAt(i));
                            }
                        }
                    }

                    double spam = myBayes.CBayes(values);

                    if (spam > 0.3)
                    {
                        listBox2.Items.Add(body + myBayes.CBayes(values));
                    }
                    else
                    {
                        listBox1.Items.Add(body);
                    }
                    values.Clear();
                }
            }
        }
Exemplo n.º 4
0
        private void Form2_Load(object sender, EventArgs e)
        {
            using (Imap imap = new Imap())
            {
                imap.ConnectSSL("imap." + client);
                imap.Login(login, password);

                CommonFolders folders = new CommonFolders(imap.GetFolders());
                imap.Select(folders.Spam);

                MailBuilder builder = new MailBuilder();
                counter = 0;
                foreach (long uid in imap.Search(Flag.All))
                {
                    counter++;
                    IMail         email     = builder.CreateFromEml(imap.GetMessageByUID(uid));
                    string        text      = email.Subject + " " + email.Text;
                    List <string> canontext = myCanonize.canonize(text);
                    foreach (string row in canontext)
                    {
                        if (row == "")
                        {
                            continue;
                        }
                        if (!tokens.ContainsKey(row))
                        {
                            tokens.Add(row, 1);
                        }
                        else
                        {
                            tokens[row]++;
                        }
                    }
                }

                tokens = tokens.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
                for (int i = 0; i < 15; i++)
                {
                    canonlist.Add(tokens.ElementAt(i).Key);
                    percentSpam.Add(Convert.ToDouble(tokens.ElementAt(i).Value) * 100 / Convert.ToDouble(counter));
                }
            }
        }
Exemplo n.º 5
0
        //public void SendMessage()
        //{
        //    try
        //    {
        //        MailAddress fromMailAddress = new MailAddress("*****@*****.**");
        //        MailAddress toAddress = new MailAddress("*****@*****.**");

        //        using (MailMessage mailMessage = new MailMessage(fromMailAddress, toAddress))
        //        using (SmtpClient smtpClient = new SmtpClient("smtp.ukr.net", 465))
        //        {
        //            mailMessage.Subject = "Test Email";
        //            mailMessage.Body = "Helllllooo!!!";

        //            smtpClient.Credentials = new NetworkCredential(fromMailAddress.Address, "kdocument_2021");
        //            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        //            smtpClient.EnableSsl = true;
        //            smtpClient.UseDefaultCredentials = false;

        //            smtpClient.Send(mailMessage);
        //            MessageBox.Show("Email sent successfully!");
        //        }
        //    }
        //    catch (IOException ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
        //}

        public void TestSendMessage()
        {
            try
            {
                MailBuilder builder = new MailBuilder();
                builder.Subject = String.Format("Тестовий лист - {0}", senderNameCmb.Text);
                builder.From.Add(new MailBox(emailTxb.Text, emailTxb.Text));
                builder.To.Add(new MailBox(emailTxb.Text));
                builder.Text = "Це електронний лист із простим текстом";

                IMail email = builder.Create();

                using (Smtp smtp = new Smtp())
                {
                    smtp.ConnectSSL(sendingMailTxb.Text);
                    smtp.Configuration.EnableChunking = true;
                    smtp.UseBestLogin(sendingLoginCmb.Text, sendingPasswordTxb.Text);
                    smtp.SendMessage(email);
                    MessageBox.Show("Електронний лист успішно надіслано!");
                }

                using (Imap imap = new Imap())
                {
                    imap.ConnectSSL(receivingMailTxb.Text);
                    imap.UseBestLogin(receivingLoginCmb.Text, receivingPasswordTxb.Text);

                    CommonFolders folders = new CommonFolders(imap.GetFolders());
                    imap.UploadMessage(folders.Sent, email);

                    imap.Close();
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 6
0
 private void TestingMSN()
 {
     try
     {
         using (Imap client = new Imap())
         {
             client.ConnectSSL("imap.aol.com");
             client.UseBestLogin("*****@*****.**", "acidfreak123");
             // MessageBox.Show(client.Connected.ToString());
             CommonFolders folders = new CommonFolders(client.GetFolders());
             client.Select(folders.Spam);
             foreach (long msg in client.GetAll())
             {
                 // MessageBox.Show(client.GetMessageByUID(msg));
                 client.FlagMessageByUID(msg, Flag.Seen);
                 client.MoveByUID(msg, folders.Inbox);
             }
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 7
0
        private void startprocess(string logindetails, string imapselect, bool sendmail, string smtptet)
        {
            try
            {
                int    type   = 0;
                Socket socket = null;

                if (proxies.Count > 0)
                {
                    type = 1;
                    ProxyFactory factory = new ProxyFactory();
                    string       proxi   = proxies[rad.Next(proxies.Count)];
                    string[]     prox    = proxi.Split(':');
                    IProxyClient proxy   = null;
                    if (prox.Length == 4)
                    {
                        proxy = factory.CreateProxy(ProxyType.Http, prox[0], Convert.ToInt32(prox[1]), prox[2], prox[3]);
                    }
                    else
                    {
                        proxy = factory.CreateProxy(ProxyType.Http, prox[0], Convert.ToInt32(prox[1]));
                    }
                    socket = proxy.Connect(imapselect, Imap.DefaultSSLPort);
                }
                using (Imap imap = new Imap())
                {
                    if (type == 0)
                    {
                        imap.ConnectSSL(imapselect);
                    }
                    else
                    {
                        imap.AttachSSL(socket, imapselect);
                    }
                    string[] cred = logindetails.Split(':');
                    imap.Login(cred[0], cred[1]);                   // You can also use: LoginPLAIN, LoginCRAM, LoginDIGEST, LoginOAUTH methods,
                    CommonFolders folders = new CommonFolders(imap.GetFolders());
                    imap.Select(folders.Spam);
                    foreach (long ouid in imap.GetAll())
                    {
                        IMail email = new MailBuilder().CreateFromEml(
                            imap.GetMessageByUID(ouid));

                        List <long> unseenReports = new List <long>();
                        foreach (string sub in subjects)
                        {
                            if (email.Subject.Contains(sub) || string.Equals(email.Subject, sub))
                            {
                                unseenReports.Add(ouid);

                                if (!checkBox1.Checked && sendmail && !radioButton4.Checked)
                                {
                                    IMail  original = email;
                                    Socket socket1  = null;
                                    if (proxies.Count > 0)
                                    {
                                        type = 1;
                                        ProxyFactory factory = new ProxyFactory();
                                        string       proxi   = proxies[rad.Next(proxies.Count)];
                                        string[]     prox    = proxi.Split(':');
                                        IProxyClient proxy   = null;
                                        if (prox.Length == 4)
                                        {
                                            proxy = factory.CreateProxy(ProxyType.Http, prox[0], Convert.ToInt32(prox[1]), prox[2], prox[3]);
                                        }
                                        else
                                        {
                                            proxy = factory.CreateProxy(ProxyType.Http, prox[0], Convert.ToInt32(prox[1]));
                                        }
                                        socket1 = proxy.Connect(smtptet, portsmtp);
                                    }
                                    ReplyBuilder replyBuilder = original.Reply();

                                    // You can specify your own, custom, body and subject templates:
                                    replyBuilder.HtmlReplyTemplate    = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
    <html>
    <head>
        <meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8"" />
        <title>[Subject]</title>
    </head>
    <body>
    [Html]
    <br /><br />
    On [Original.Date] [Original.Sender.Name] wrote:
    <blockquote style=""margin-left: 1em; padding-left: 1em; border-left: 1px #ccc solid;"">
        [QuoteHtml]
    </blockquote>
    </body>
    </html>";
                                    replyBuilder.SubjectReplyTemplate = "Re: [Original.Subject]";

                                    replyBuilder.Html = NewSpin.Spin(textBox1.Text);

                                    MailBuilder builder = replyBuilder.ReplyToAll(cred[0]);

                                    // You can add attachments to your reply
                                    //builder.AddAttachment("report.csv");

                                    IMail reply = builder.Create();
                                    using (Smtp smtp = new Smtp())
                                    {
                                        if (type == 0)
                                        {
                                            if (radioButton3.Checked || radioButton4.Checked)
                                            {
                                                smtp.Connect(smtptet, portsmtp);
                                                smtp.StartTLS();
                                            }
                                            else
                                            {
                                                smtp.ConnectSSL(smtptet, portsmtp);
                                            }
                                        }
                                        else
                                        {
                                            if (radioButton3.Checked || radioButton4.Checked)
                                            {
                                                smtp.Attach(socket1);
                                                smtp.StartTLS();
                                            }
                                            else
                                            {
                                                smtp.AttachSSL(socket1, smtptet);
                                            }
                                        }
                                        smtp.ReceiveTimeout = new TimeSpan(0, 0, 100);
                                        //MessageBox.Show("Sending Mail");
                                        smtp.UseBestLogin(cred[0], cred[1]);
                                        smtp.SendMessage(reply);
                                        smtp.Close();
                                    }
                                }
                            }
                        }

                        foreach (long uid in unseenReports)        // Download emails from the last result.
                        {
                            // MessageBox.Show(uid.ToString());
                            imap.MoveByUID(uid, folders.Inbox);

                            imap.FlagMessageByUID(uid, Flag.Seen);
                            movedcount = movedcount + 1;
                        }
                    }
                    imap.Close();
                }
            }
            catch (Exception exp)
            {
                //MessageBox.Show(exp.ToString());
            }
            finally
            {
                count = count + 1;
            }
        }