I have a program that is sending a base64url encoded string, but I read in places that the '\' character isn't supported by base64. My purpose is to send emails with the Gmail API in Go. The body part consists of the following:
"Name: \n\nThis is the body of the email\n\nSincerely,\nSenderName"
When I send emails through the Gmail API, I need to pass it a base64url string. I have the following function to handle that:
func encodeWeb64String(b []byte) string {
s := base64.URLEncoding.EncodeToString(b)
var i = len(s) - 1
for s[i] == '=' {
i--
}
return s[0 : i+1]
}
I have already added the header information to msg following this post, and have set the content type to text/html; charset=\"utf-8\"
. I then create the Gmail message using this:
gmsg := gmail.Message{
Raw: encodeWeb64String([]byte(msg)),
}
When the email comes through, it looks like this:
Name: This is the body of the email Sincerely, SenderName
But I want each '\n' to put in actual newline. Thanks for any help, I am new with the Gmail API for Go.
I finally fixed it. I had to change the content type from text/html
to text/plain
, and now the newlines show properly on the email client