.Net POP3 client [duplicate]

被刻印的时光 ゝ 提交于 2019-12-11 01:46:26

问题


.net has a SMTP client for sending mail but no pop3 client for reading mail. Ive used WEBDAV before, but I really want a simple pop3 or imap client thats stable

I know there seems to be 10000 of examples, but why no offical .net client if they made a SMTP client

any thoughts?


回答1:


The F#.NET Journal article An e-mail client in F# (31st March 2010) describes how you can write your own in just a few lines of F# code, centered around the following sequence expression:

> let receive =
    seq { use client = new Sockets.TcpClient(Server.pop3.addr, Server.pop3.port)
          use stream = client.GetStream()
          use reader = new System.IO.StreamReader(stream)
          let rec readToDot() =
            let line = reader.ReadLine()
            if line <> "." then line + "\n" + readToDot() else ""
          reader.ReadLine() |> ignore
          use writer = new System.IO.StreamWriter(stream)
          let write (line: string) =
            writer.Write(line + "\n")
            writer.Flush()
          write "USER myname"
          reader.ReadLine() |> ignore // +OK Password required.
          write "PASS mypassword"
          reader.ReadLine() |> ignore // +OK logged in.
          write "STAT"
          let stat = reader.ReadLine() // +OK <message count> <total size>
          for i in 1 .. int (stat.Split[|' '|]).[1] do
            write(sprintf "RETR %d" i)
            reader.ReadLine() |> ignore // +OK <message size> octets follow.
            match readToDot() |> parse with
            | Some msg -> yield msg
            | None -> ()
          write "QUIT"
          reader.ReadLine() |> ignore };;
val receive : seq<msg>



回答2:


This is the library I used. It was very easy to use, didn't have any problems with it.



来源:https://stackoverflow.com/questions/3149892/net-pop3-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!