Exemple #1
0
 public void DeleteMail(String uid)
 {
     using (Pop3 mailClient = CreateMailClient())
     {
         mailClient.DeleteMessageByUID(uid);
         mailClient.Close();
     }
 }
Exemple #2
0
 void DelMail()
 {
     if (idmail != "0")
     {
         pop3.DeleteMessageByUID(idmail);
         foreach (DataRow row in dtmail.Rows)
         {
             if (idmail == row["id"].ToString())
             {
                 dtmail.Rows.Remove(row);
                 dtmail.AcceptChanges();
                 break;
             }
         }
         dataGridView_Mail.DataSource = dtmail;
     }
 }
        static void Main(string[] args)
        {
            string[] arg;
            int      flag = 0;

            arg = System.Environment.GetCommandLineArgs();
            string path = @"e:\!email-mikrotik\";

            for (int i = 0; i < arg.Length; i++)
            {
                if (arg[i] == "/dir")
                {
                    if (!String.IsNullOrEmpty(arg[i + 1]))
                    {
                        path = arg[i + 1];
                    }
                }
                if (arg[i] == "-debug")
                {
                    flag = 1;
                }

                if (arg[i] == "/?")
                {
                    Console.WriteLine("");
                    Console.WriteLine("Использование: mail2dirr.exe /dir \"папка для вложений\" [-debug] ");

                    return;
                }
            }

            //string path_base = @"e:\!email-mikrotik\";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (path.Substring(path.Length - 1) != @"\")
            {
                path += @"\";
            }
            using (Pop3 pop3 = new Pop3())
            {
                try
                {
                    pop3.Connect("pop.i.ua");       // or ConnectSSL for SSL
                    pop3.UseBestLogin("*****@*****.**", "dtnjxrfcbhtyb500");
                    foreach (string uid in pop3.GetAll())
                    {
                        IMail email = new MailBuilder()
                                      .CreateFromEml(pop3.GetMessageByUID(uid));
                        //бесплатная библиотека мусорит сабжект письма
                        string filenam;
                        filenam = @email.Text.Replace("/", "-");
                        filenam = email.Text.Replace("\r\n", "");
                        // email.Save(@"e:\1111qa");
                        foreach (MimeData mime in email.Attachments)
                        {
                            mime.Save(path + mime.SafeFileName);
                        }
                    }
                    //удаляем сообщения с сервера
                    foreach (string uid in pop3.GetAll())
                    {
                        pop3.DeleteMessageByUID(uid);
                    }
                    pop3.Close();
                }
                catch (Exception e) {
                    if (flag != 0)
                    {
                        MessageBox((IntPtr)0, e.ToString(), "mail_UDProgram_message", 0);
                    }
                    //path += "ok.ok"; if (!File.Exists(path)) File.Create(path);
                }
            }
            //ставим знак окончания приема писем
            path += "ok.ok"; if (!File.Exists(path))
            {
                File.Create(path);
            }
        }
Exemple #4
0
        private void ReadMailBox(Configuration config)
        {
            log.Info("Check for Mail");
            if (!string.IsNullOrEmpty(config.AppSettings.Settings["POPServer"].Value))
            {
                try
                {
                    if (config.AppSettings.Settings["MailType"].Value == "POP")
                    {
                        using (Pop3 pop3 = new Pop3())
                        {
                            pop3.ServerCertificateValidate +=
                                new ServerCertificateValidateEventHandler(Validate);


                            pop3.ConnectSSL(config.AppSettings.Settings["POPServer"].Value);
                            //pop3.STLS();
                            pop3.Login(config.AppSettings.Settings["POPMailUser"].Value, config.AppSettings.Settings["POPMailPassword"].Value);

                            foreach (string uid in pop3.GetAll())
                            {
                                string eml  = pop3.GetMessageByUID(uid);
                                IMail  mail = new MailBuilder()
                                              .CreateFromEml(eml);

                                try
                                {
                                    mail.Attachments.ForEach(att =>
                                    {
                                        processAttachment(att, config, mail.Sender.Address);
                                    });
                                    pop3.DeleteMessageByUID(uid);
                                }
                                catch (IOException ex)
                                {
                                    log.Error(ex.InnerException);
                                }
                                catch (Exception ex)
                                {
                                    log.Error(ex);
                                }
                            }
                            pop3.Close();
                        }
                    }
                    else
                    {
                        #region IMAP
                        Imap imap = new Imap();

                        //imap.User = ;

                        //imap.Password =;
                        imap.Connect(config.AppSettings.Settings["POPServer"].Value);
                        imap.Login(config.AppSettings.Settings["POPMailUser"].Value, config.AppSettings.Settings["POPMailPassword"].Value);

                        imap.SelectInbox();

                        List <long> uidList = imap.SearchFlag(Flag.Unseen);
                        log.Debug("Go to process: " + uidList.Count + "mails");

                        foreach (long uid in uidList)
                        {
                            ISimpleMailMessage imail = new SimpleMailMessageBuilder()

                                                       .CreateFromEml(imap.GetMessageByUID(uid));

                            log.Info("Email received: " + imail.From.First().Name);

                            foreach (var att in imail.Attachments)
                            {
                                try
                                {
                                    processAttachment(att, config, imail.From.First().Address);
                                }
                                catch (IOException ex)
                                {
                                    log.Error(ex.InnerException);
                                    imap.FlagMessageByUID(uid, Flag.Flagged);
                                    imap.MarkMessageSeenByUID(uid);
                                }
                                catch (Exception ex)
                                {
                                    log.Error(ex);
                                    imap.FlagMessageByUID(uid, Flag.Flagged);
                                    imap.MarkMessageSeenByUID(uid);
                                }
                            }

                            imap.MarkMessageSeenByUID(uid);
                            imap.DeleteMessageByUID(uid);
                        }

                        imap.Close(true);
                        #endregion
                    }
                    log.Info("Mail check complete");
                }
                catch (Exception ex)
                {
                    log.Error(ex.InnerException);
                }
            }
            else
            {
                log.Info("Mail check skipped!");
            }
        }