How to save email attachment using OpenPop

前端 未结 7 945
渐次进展
渐次进展 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:22

    I wrote this quite a long time ago, but have a look at this block of code that I used for saving XML attachments within email messages sat on a POP server:

    OpenPOP.POP3.POPClient client = new POPClient("pop.yourserver.co.uk", 110, "your@email.co.uk", "password_goes_here", AuthenticationMethod.USERPASS); 
    if (client.Connected) {
    int msgCount = client.GetMessageCount();
    
    /* Cycle through messages */
    for (int x = 0; x < msgCount; x++)
        {
            OpenPOP.MIMEParser.Message msg = client.GetMessage(x, false);
            if (msg != null) {
                for (int y = 0; y < msg.AttachmentCount; y++)
                {
                    Attachment attachment = (Attachment)msg.Attachments[y];
    
                    if (string.Compare(attachment.ContentType, "text/xml") == 0)
                    {
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
    
                        string xml = attachment.DecodeAsText();
                        doc.LoadXml(xml);
                        doc.Save(@"C:\POP3Temp\test.xml");
                    }
                }
            }
        }
    }
    

提交回复
热议问题