1.在windows系统下,需要首先定义两个环境变量GOPATH和GOROOT, GOPATH是第三方类库的代码目录 , GOROOT是go的安装目录
2.按照我的定义 , 进入这个目录D:\golang\code\src\github.com\emersion , 使用git 更新代码
git clone https://github.com/emersion/go-imap.git
git clone https://github.com/emersion/go-sasl.git
package mainimport ("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.Clientvar err errorlog.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.Messageslog.Printf("%s : %d", m.Name, to)} }