Beispiel #1
0
func main() {
	cacheFile := filepath.Join("./.credentials", url.QueryEscape("gmail_token.json"))

	config, err := conflib.CreateGmailConfig()
	if err != nil {
		log.Fatalf("Unable to parse client secret file to config: %v", err)
	}
	token := getTokenFromWeb(config)

	saveToken(cacheFile, token)
}
Beispiel #2
0
func main() {
	ctx := context.Background()

	config, err := conflib.CreateGmailConfig()
	if err != nil {
		log.Fatalf("Unable to parse client secret file to config: %v", err)
	}
	client := getClient(ctx, config)

	srv, err := gmail.New(client)
	if err != nil {
		log.Fatalf("Unable to retrieve gmail Client %v", err)
	}
	_ = srv

	draftMap, err := loadBodyFile()
	if err != nil {
		log.Fatalf("Unable to parse draft template file to map structure: %v", err)
	}
	toStr, subStr, msgStr := createDraftsStr(draftMap)

	header, _ := toISO2022JP(toStr + subStr)
	msg := []byte(msgStr)
	bodyBytes := append(header, msg...)
	message := gmail.Message{}
	message.Raw = base64.URLEncoding.EncodeToString(bodyBytes)

	user := "******"
	draft := gmail.Draft{
		Message: &message,
	}
	_, err = srv.Users.Drafts.Create(user, &draft).Do()
	if err != nil {
		log.Fatalf("Unable to create drafts: %v", err)
	}
}