Ejemplo n.º 1
0
func main() {
	cfg := mail.Config{
		SecretFile: "client_secret.json",
	}
	c, err := mail.NewClient(cfg)
	if err != nil {
		log.Fatalf("Failed to new mail client: %v", err)
	}

	msgs, err := c.FetchUnread()
	if err != nil {
		log.Fatalf("Failed to fetch unread messages: %v", err)
	}

	for _, m := range msgs {
		fmt.Printf("\nMessage URL: https://mail.google.com/mail/u/0/#all/%v\n", m.Id)
		fmt.Printf("Subject: %s\n", m.Subject)
		fmt.Printf("From: %s\n", m.From)
		fmt.Printf("To: %s\n", strings.Join(m.To, ", "))
		fmt.Printf("Body: %s\n", m.Body)

		fmt.Printf("Options: (t)rash, (s)kip, (q)uit: [s] ")
		var op string
		if _, err = fmt.Scan(&op); err != nil {
			log.Fatalf("Failed to read operation: %v", err)
		}
		op = strings.TrimSpace(op)
		switch op {
		case "t": // trash message
			if err = c.Trash(m.Id); err != nil {
				log.Fatalf("Failed to trash message %v: %v", m.Id, err)
			}
			log.Printf("Trash message %v.\n", m.Id)
		case "q": // quit
			log.Printf("Done.\n")
			os.Exit(0)
		default:
		}
	}
}
Ejemplo n.º 2
0
func main() {
	cfg := mail.Config{
		SecretFile: "client_secret.json",
	}
	c, err := mail.NewClient(cfg)
	if err != nil {
		log.Fatalf("Failed to new mail client: %v", err)
	}

	msg := mailproto.Message{
		To: []string{
			"*****@*****.**",
			"*****@*****.**",
			"*****@*****.**",
		},
		Subject: "Use qiniu.com/gmail/mail package",
		Body:    "Hiiiiii, send mail, 233333!!!",
	}
	id, err := c.Send(&msg)
	if err != nil {
		log.Fatalf("Failed to send mail: %v", err)
	}
	fmt.Println("Id:", id)
}