当前位置: 首页>>代码示例>>C#>>正文


C# Pop3Client.Dispose方法代码示例

本文整理汇总了C#中OpenPop.Pop3.Pop3Client.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Pop3Client.Dispose方法的具体用法?C# Pop3Client.Dispose怎么用?C# Pop3Client.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenPop.Pop3.Pop3Client的用法示例。


在下文中一共展示了Pop3Client.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: segundoplano_DoWork

 private void segundoplano_DoWork(object sender, DoWorkEventArgs e)
 {
     Pop3Client emaiClient = new Pop3Client();
     try
     {
         emaiClient.Connect(servidordeemail.Text, Convert.ToInt32(porta.Value), SSL);
         emaiClient.Authenticate(usuario.Text, senha.Text);
         if (!emaiClient.Connected) return;
         var messages = new List<OpenPop.Mime.Message>();
         Total_de_Emails = emaiClient.GetMessageCount();
         for (var i = 1; i < Total_de_Emails; i++)
         {
             messages.Add(emaiClient.GetMessage(i));
             segundoplano.ReportProgress(i);
         }
         Total_de_Emails = messages.Count;
         int x = 0;
         foreach (var msg in messages.Where(y => DateTime.Parse(y.Headers.Date) >= DataInicial && DateTime.Parse(y.Headers.Date) <= DataFinal && y.FindAllAttachments() != null))
         {
             x++;
             var anexo = msg.FindAllAttachments();
             foreach (var ado in anexo.Where(c => c.FileName.EndsWith(".xml")))
             {
                 ado.Save(new FileInfo(Path.Combine(Caminho, ado.FileName)));
             }
             segundoplano.ReportProgress(x);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
     finally
     {
         if (emaiClient.Connected)
         {
             emaiClient.Disconnect();
             emaiClient.Dispose();
         }
     }
 }
开发者ID:carloshenriquecarniatto,项目名称:Baixa-Anexos-Email,代码行数:41,代码来源:Inicial.cs

示例2: RetrieveEmails

        public void RetrieveEmails(string EmailAddress, string Password, string ConnString, string DeleteMessage, string HostName, int Port, bool UseSsl, bool sendreceivedemail, bool SendOverDueReceivedEmail)
        {
            Pop3Client client = new Pop3Client();

            client.Connect(HostName, Port, UseSsl);//the type of server

            client.Authenticate(EmailAddress, Password);//connects to the inbox we want to get the emails from

            int Count = client.GetMessageCount();//gets the message count for the inbox of the above email

            for (int i = 1; i <= Count; i++)//loops through the messages in the inbox
            {
                OpenPop.Mime.Message message = client.GetMessage(i);//gets the message 

                string email = message.Headers.From.Address.ToString();//this gets the email address

                string subject = message.Headers.Subject.ToString();//this gets the subject

                string Parent = getBetween(subject, "(", ")");

                int parent;

                try
                {
                    parent = Convert.ToInt32(Parent);
                }

                catch
                {
                    parent = 0;
                }

                string body = message.FindFirstPlainTextVersion().GetBodyAsText();//this gets the body

                int ticketid = AddEmailToDatabase(ConnString, email, subject, body, parent);//this add the email message to the database and returns its ticketid

                if (parent == 0)
                {
                    if (sendreceivedemail == true)
                    {
                        SendReceivedEmail(ConnString, email, EmailAddress, Password, ticketid);//sends an email back saying we received there email
                    }
                }

                foreach (OpenPop.Mime.MessagePart emailattachment in message.FindAllAttachments())//this loops through all the attachments for a message
                {
                    string OriginalFileName = emailattachment.FileName;//gets the original file name of the attachment

                    string ContentID = emailattachment.ContentId;//if this is set then the attachment is inline.

                    string ContentType = emailattachment.ContentType.MediaType;//type of attachment pdf, jpg, png, etc.

                    byte[] Content = emailattachment.Body;//gets the body of the attachment as a byte[]

                    using (MemoryStream MS = new MemoryStream(Content))//puts the Content[] into a memory stream
                    {

                        Image im = Image.FromStream(MS, true, true);//Image from the memorystream

                        int sourceWidth = im.Width;//the original width of the image

                        int sourceHeight = im.Height;//the original height of the image

                        float nPercent = 0;

                        float nPercentW = 0;

                        float nPercentH = 0;
                        //the following code checks which is larger the height or width and then resizes the image accordingly
                        nPercentW = ((float)900 / (float)sourceWidth);

                        nPercentH = ((float)900 / (float)sourceHeight);

                        if (nPercentH < nPercentW)
                            nPercent = nPercentH;
                        else
                            nPercent = nPercentW;

                        int destWidth = (int)(sourceWidth * nPercent);
                        int destHeight = (int)(sourceHeight * nPercent);

                        Bitmap b = new Bitmap(destWidth, destHeight);
                        Graphics g = Graphics.FromImage((Image)b);
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                        g.DrawImage(im, 0, 0, destWidth, destHeight);
                        g.Dispose();

                        MemoryStream m = new MemoryStream();

                        b.Save(m, ImageFormat.Jpeg);

                        Content = m.ToArray();
                    }

                    AddAttachmentToDatabase(ConnString, ticketid, OriginalFileName, Content);//adds the attachment to the database

                    //write the attachment to the disk
                    //System.IO.File.WriteAllBytes("C:/Users/David/Documents/Visual Studio 2012/Projects/GetEmails/GetEmails/Attachments/" +ticketid+ OriginalFileName, emailattachment.Body);//overwrites MessagePart.Body with attachment

//.........这里部分代码省略.........
开发者ID:douglashughjackson,项目名称:TicketService,代码行数:101,代码来源:Email.cs

示例3: StartCheck


//.........这里部分代码省略.........

                List<string> listWrongEmails = new List<string>();

                DateTime dtCurrDateSent = DateTime.Now;

                pop3Client.Connect(mailServerPop3, mailServerPop3Port, true);
                pop3Client.Authenticate(mailFrom, mailFromPassword);

                Message message = null;
                int countMessages = pop3Client.GetMessageCount();
                for (int i = 1; i <= countMessages; i++)
                {
                    message = pop3Client.GetMessage(i);
                    if (message != null && message.Headers != null && message.Headers.DateSent != null &&
                        message.Headers.From.Address == mailDeliverySubsystemEmail)
                    {
                        dtCurrDateSent = message.Headers.DateSent;
                        if (message.Headers.DateSent.Kind == DateTimeKind.Utc)
                        {
                            dtCurrDateSent = message.Headers.DateSent.ToLocalTime();
                        }

                        if (this.dtStartDateSend <= dtCurrDateSent && dtCurrDateSent <= DateTime.Now)
                        {
                            if (message.MessagePart != null && message.MessagePart.GetBodyAsText().Split('\r', '\n').Where(w => w.Contains("@")).Count() > 0)
                            {
                                string wrongEmail = message.MessagePart.GetBodyAsText().Split('\r', '\n').Where(w => w.Contains("@")).First().Trim();

                                listWrongEmails.Add(wrongEmail);
                            }
                        }
                    }
                }

                List<Person> listPersonsWithWrongEmails = new List<Person>();

                ETEMDataModelEntities dbContext = new ETEMDataModelEntities();

                listPersonsWithWrongEmails = (from p in dbContext.Persons
                                              where listWrongEmails.Contains(p.EMail)
                                              orderby p.FirstName ascending, p.SecondName ascending, p.LastName ascending
                                              select p).ToList<Person>();

                if (listPersonsWithWrongEmails.Count > 0)
                {
                    string subject = (from kv in dbContext.KeyValues
                                      join kt in dbContext.KeyTypes on kv.idKeyValue equals kt.idKeyType
                                      where kt.KeyTypeIntCode == ETEMEnums.KeyTypeEnum.EmailSubject.ToString() &&
                                            kv.KeyValueIntCode == ETEMEnums.EmailSubjectEnum.WrongSentEmails.ToString()
                                      select kv.Description).FirstOrDefault();

                    string body = (from kv in dbContext.KeyValues
                                   join kt in dbContext.KeyTypes on kv.idKeyValue equals kt.idKeyType
                                   where kt.KeyTypeIntCode == ETEMEnums.KeyTypeEnum.EmailSubject.ToString() &&
                                         kv.KeyValueIntCode == ETEMEnums.EmailBodyEnum.WrongSentEmails.ToString()
                                   select kv.Description).FirstOrDefault();

                    if (!string.IsNullOrEmpty(subject) && !string.IsNullOrEmpty(body))
                    {
                        string bodyInnerText = string.Empty;
                        foreach (Models.Person person in listPersonsWithWrongEmails)
                        {
                            if (string.IsNullOrEmpty(bodyInnerText))
                            {
                                bodyInnerText += BaseHelper.GetCaptionString("Email_WrongSentEmail_Email") + " " + person.EMail + "\n";
                                bodyInnerText += BaseHelper.GetCaptionString("Email_WrongSentEmail_PersonName") + " " + person.FullName;
                            }
                            else
                            {
                                bodyInnerText += "\n" + BaseHelper.GetNumberOfCharAsString('-', 100) + "\n";

                                bodyInnerText += BaseHelper.GetCaptionString("Email_WrongSentEmail_Email") + " " + person.EMail + "\n";
                                bodyInnerText += BaseHelper.GetCaptionString("Email_WrongSentEmail_PersonName") + " " + person.FullName;
                            }
                        }

                        body = string.Format(body, bodyInnerText);

                        SendMailAction(mailFrom, mailTo, subject, body);
                    }
                }
            }
            catch (Exception ex)
            {
                BaseHelper.Log("Грешка при проверка за неуспешно изпратени имейли - (ThreadCheckForWrongEmails.StartCheck)!");
                BaseHelper.Log(ex.Message);
                BaseHelper.Log(ex.StackTrace);
            }
            finally
            {
                if (pop3Client != null)
                {
                    if (pop3Client.Connected)
                    {
                        pop3Client.Disconnect();
                    }
                    pop3Client.Dispose();
                }
            }
        }
开发者ID:borisov90,项目名称:Projects,代码行数:101,代码来源:ThreadCheckForWrongEmails.cs


注:本文中的OpenPop.Pop3.Pop3Client.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。