1 回答

TA貢獻1862條經驗 獲得超6個贊
我相信你的目標如下。
您想使用 googleapis for golang 發送電子郵件。
您已經能夠使用 Gmail API 獲取和發送電子郵件。
修改點:
在您的腳本中,我認為
mailtext
需要對其進行修改。在這種情況下,換行符和空格很重要。雖然
raw
已創建,但并未放入請求正文。
當以上幾點反映到您的腳本時,它變成如下。
修改后的腳本:
從:
mailtext := `
From: [email protected]
Subject: Saying Hello
Date: Thu, 8 Oct 2020 09:55:06 -0600
Message-ID: <[email protected]>
This is a message just to say hello.
So, "Hello".
`
raw := base64.URLEncoding.EncodeToString([]byte(mailtext))
// create gmail.Message
var message gmail.Message
message.Id = "Msg 1"
message.LabelIds = []string{"SENT"}
至:
user := "me"
// Modified
mailtext := `From: [email protected]
Subject: Saying Hello
Date: Thu, 8 Oct 2020 09:55:06 -0600
Message-ID: <[email protected]>
This is a message just to say hello.
So, "Hello".`
raw := base64.URLEncoding.EncodeToString([]byte(mailtext))
// create gmail.Message
var message gmail.Message
message.Id = "Msg 1"
message.LabelIds = []string{"SENT"}
message.Raw = raw // Added
我認為在這種情況下,Date:可能Message-ID:會被新的價值觀所取代。
或者,請mailtext進行如下修改。
mailtext := "From: [email protected]\nTo: [email protected]\nSubject: Saying Hello\nDate: Thu, 8 Oct 2020 09:55:06 -0600\nMessage-ID: <[email protected]>\n\nThis is a message just to say hello.\nSo, \"Hello\"."
- 1 回答
- 0 關注
- 219 瀏覽
添加回答
舉報