zoukankan      html  css  js  c++  java
  • 使用OpenPop.Net收取邮件

     Console.WriteLine("OpenPop.Pop3.Pop3Client:");
                try
                {
    
                    using (var client = new OpenPop.Pop3.Pop3Client())
                    {
                        client.Connect(host, port, false);
                        client.Authenticate(address, password);
                        var count = client.GetMessageCount();
                        for (int i = count; i > 0; i--)
                        {
                            OpenPop.Mime.Message message = client.GetMessage(i);
                            Console.WriteLine("Subject:" + message.Headers.Subject);
                            var messagePart = message.MessagePart;
                            string body = " ";
                            if (messagePart.IsText)
                            {
                                body = messagePart.GetBodyAsText();
                            }
                            else if (messagePart.IsMultiPart)
                            {
                                var plainTextPart = message.FindFirstPlainTextVersion();
                                if (plainTextPart != null)
                                {
    
                                    body = plainTextPart.GetBodyAsText();
                                }
                                else
                                {
    
                                    List<MessagePart> textVersions = message.FindAllTextVersions();
                                    if (textVersions.Count >= 1)
                                        body = textVersions[0].GetBodyAsText();
                                    else
                                        body = "<<OpenPop>> Cannot find a text version body in this message.";
                                }
                                Console.WriteLine("body:" + body);
    
                                //遍历并获取邮件附件
                                foreach (MessagePart attachment in message.FindAllAttachments())
                                {
                                    Console.WriteLine("FileName:" + attachment.FileName);
                                    //File.WriteAllBytes(attachment.FileName, attachment.Body);
                                }
    
                            }
    
    
                        }
                     
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

    Nuget引用OpenPop.Net到项目中

    OpenPop.Pop3.Pop3Client对象连接服务器

    支持POP3IMAP协议,

    host, port保证正确就能连接,
    address, password保证正确就能登录
  • 相关阅读:
    2018-8-10-win10-uwp-商业游戏-1.2.1
    2018-8-10-win10-uwp-商业游戏-1.2.1
    2019-3-1-获取-Nuget-版本号
    2019-3-1-获取-Nuget-版本号
    2019-9-24-dotnet-remoting-抛出异常
    2019-9-24-dotnet-remoting-抛出异常
    2018-2-13-C#-解析-sln-文件
    2018-2-13-C#-解析-sln-文件
    2018-10-19-jekyll-添加-Valine-评论
    2018-10-19-jekyll-添加-Valine-评论
  • 原文地址:https://www.cnblogs.com/lizhenhong/p/13231168.html
Copyright © 2011-2022 走看看