How to save email attachment using OpenPop

前端 未结 7 810
渐次进展
渐次进展 2020-12-30 09:29

I have created a Web Email Application, How do I view and save attached files?

I am using OpenPop, a third Party d

相关标签:
7条回答
  • 2020-12-30 10:23

    for future readers there is easier way with newer releases of Pop3

    using( OpenPop.Pop3.Pop3Client client = new Pop3Client())
            {
                client.Connect("in.mail.Your.Mailserver.com", 110, false);
                client.Authenticate("usernamePop3", "passwordPop3", AuthenticationMethod.UsernameAndPassword);
                if (client.Connected)
                {
                    int messageCount = client.GetMessageCount();
                    List<Message> allMessages = new List<Message>(messageCount);
                    for (int i = messageCount; i > 0; i--)
                    {
                        allMessages.Add(client.GetMessage(i));
                    }
                    foreach (Message msg in allMessages)
                    {
                        var att = msg.FindAllAttachments();
                        foreach (var ado in att)
                        {
                            ado.Save(new System.IO.FileInfo(System.IO.Path.Combine("c:\\xlsx", ado.FileName)));
                        }
                    }
                }
               }
    
    0 讨论(0)
提交回复
热议问题