1.在windows系统下,需要首先定义两个环境变量GOPATH和GOROOT, GOPATH是第三方类库的代码目录 , GOROOT是go的安装目录
2.按照我的定义 , 进入这个目录D:golangcodesrcgithub.comemersion , 使用git 更新代码
git clone https://github.com/emersion/go-imap.git
git clone https://github.com/emersion/go-sasl.git
package main import ( "github.com/emersion/go-imap" "github.com/emersion/go-imap/client" "log" ) const ( server = "imap.sina.net:993" username = "shihan@sopans.com" password = "xxxx" ) func main() { var c *client.Client var err error log.Println("Connecting to server...") c, err = client.DialTLS(server, nil) //连接失败报错 if err != nil { log.Fatal(err) } log.Println("Connected") //登陆 if err := c.Login(username, password); err != nil { log.Fatal(err) } log.Println("Logged in") mailboxes := make(chan *imap.MailboxInfo, 20) go func() { c.List("", "*", mailboxes) }() //列取邮件夹 for m := range mailboxes { mbox, err := c.Select(m.Name, false) if err != nil { log.Fatal(err) } to := mbox.Messages log.Printf("%s : %d", m.Name, to) } }