问题
.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