2
Goで「google.golang.org/api/gmail/v1」を使用して、HTMLコンテンツを含む複数のメールを送信しています。私はforループを使用して、さまざまなコンテンツを持つ複数のメールを送信しますが、すべて「html」タイプです。gmail-api:メールコンテンツの形式が歪んでいます(コードLang:Go)
APIが考慮されている限り、正常に動作しており、すべてのメールが配信されています。しかし、最初のメールのみが正しいフォーマット、つまりHTMLで配信されます(つまり、メールの受信者がHTML形式でメールを取得しています)。残りのユーザーはすべてのコンテンツをTEXTとしてメールを取得していますタグはメール本文に表示されます)/
成功するために必要な制限や条件はありますか?
間違いを指摘しています。
コードスニペットは、次のとおりです。
func main() {
// Get the data from the DB
recipientsList := dbRetrieval()
fmt.Println("About to call the method")
// Invoke the Loop for all the recipients
for indx := range recipientsList {
time.Sleep(time.Second * 10)
fmt.Println("The 3 second wait :", indx)
tokenValueToBeUsed := requestRefreshToken(recipientsList[indx])
if len(tokenValueToBeUsed) == 0 {
err_uid := updateIsDeleted(recipientsList[indx].UserId)
if err_uid {
fmt.Println("Zero refresh token , so updated the DELETE")
} else {
fmt.Println("Zero refresh token But couldnt update the DELETE ")
}
} else {
secret, err := ioutil.ReadFile("client_secret.json")
if err != nil {
log.Printf("Error: %v", err)
} else {
conf, err := google.ConfigFromJSON(secret, gmail.GmailSendScope)
if err != nil {
log.Printf("Error: %v", err)
} else {
var tok oauth2.Token
tok.AccessToken = tokenValueToBeUsed
token := &tok
client := conf.Client(oauth2.NoContext, token)
gmailService, err := gmail.New(client)
if err != nil {
log.Printf("Error: %v", err)
} else {
var message gmail.Message
// For HTML
header := make(map[string]string)
header["From"] = recipientsList[indx].From_Mail
header["To"] = recipientsList[indx].To_Mail
header["Subject"] = recipientsList[indx].Title + "\r\n\r\n" + recipientsList[indx].Body + "\r\n\r\n" + recipientsList[indx].Signature + "\r\n\r\n" + recipientsList[indx].Pixel
header["MIME-Version"] = "1.0"
header["Content-Type"] = "text/html; charset=\"utf-8\""
header["Content-Transfer-Encoding"] = "base64"
var msg string
for k, v := range header {
msg += fmt.Sprintf("%s: %s\r\n", k, v)
}
message.Raw = base64.URLEncoding.EncodeToString([]byte(msg))
// Send the message
_, err_gms := gmailService.Users.Messages.Send("me", &message).Do()
if err_gms != nil {
log.Printf("Error: %v", err_gms)
} else {
err_upd := updateStatus(recipientsList[indx].UUID)
if err_upd {
fmt.Println("Message sent!")
//fmt.Println("The GMAIL response Object Details", gmailResponse)
} else {
fmt.Println("Message sent! But user not updated")
}
}
}
}
}
}
}
}
ああ、すごくいいです。私はそれが問題だと思う。私はそれを試してみて、あなたに確認してみましょう。ありがとう。 – Mudit
こんにちはローマ、問題は解決しません。それは同じ振る舞いを描いています。 – Mudit
@Mudit最初のメッセージと2番目のメッセージの連結後に 'msg'を投稿できますか? –