1 回答
TA贡献1876条经验 获得超5个赞
package main
import (
"bytes"
"log"
"os"
"time"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
)
func main() {
log.Println("Connecting to server...")
// Connect to server
c, err := client.DialTLS(os.Getenv("IMAP_SERVER"), nil)
if err != nil {
log.Fatal(err)
}
log.Println("Connected")
// Don't forget to logout
defer c.Logout()
// Login
if err := c.Login(os.Getenv("IMAP_USER"), os.Getenv("IMAP_PASSWORD")); err != nil {
log.Fatal(err)
}
log.Println("Logged in")
// Write the message to a buffer
var b bytes.Buffer
b.WriteString("From: <...@gmail.com>\r\n")
b.WriteString("To: <...@gmail.com>\r\n")
b.WriteString("Subject: Append test\r\n")
b.WriteString("\r\n")
// Message body
b.WriteString("Append test using Gmail IMAP and Draft folder")
// Append it to Drafts
if err := c.Append("[Gmail]/Drafts", nil, time.Now(), &b); err != nil {
log.Fatal(err)
}
- 1 回答
- 0 关注
- 120 浏览
添加回答
举报