<分区>
.net有一个SMTP客户端用来发送邮件 但没有用于阅读邮件的 pop3 客户端。 我以前用过 WEBDAV,但我真的想要一个稳定的简单 pop3 或 imap 客户端
我知道似乎有 10000 个示例,但如果他们制作了 SMTP 客户端,为什么没有官方的 .net 客户端
有什么想法吗?
<分区>
.net有一个SMTP客户端用来发送邮件 但没有用于阅读邮件的 pop3 客户端。 我以前用过 WEBDAV,但我真的想要一个稳定的简单 pop3 或 imap 客户端
我知道似乎有 10000 个示例,但如果他们制作了 SMTP 客户端,为什么没有官方的 .net 客户端
有什么想法吗?
最佳答案
The F#.NET Journal文章 An e-mail client in F# (2010 年 3 月 31 日)描述了如何仅用几行 F# 代码编写您自己的代码,以以下序列表达式为中心:
> 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>
关于.Net POP3 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3149892/