'How can I download an Email using the Gmail api with Go

Trying to use the Go library of the Gmail API (v1) to get the raw content of a email and parse it as a byte slice {[]byte} so I can save it as an email. Any tips?



Solution 1:[1]

Looking at the package (https://pkg.go.dev/google.golang.org/api/gmail/v1#Message) it states:

// Raw: The entire email message in an RFC 2822 formatted and base64url
// encoded string. Returned in `messages.get` and `drafts.get` responses
// when the `format=RAW` parameter is supplied.

Get the email using the rfc822msgId. This can be grabbed from the header.

gmailMessageResposne, _ := gmail.Service.Users.Messages.Get("[email protected]", "rfc822msgid").Format("RAW").Do() 

Once you have the *gmail.Message object you can decode the raw string via

decodedData, _ := base64.URLEncoding.DecodeString(gmailMessageResposne.Raw)

Then

base64.URLEncoding(decodedData, decodedData)

Finally

ioutile.WriteFile("message.eml", decodedData, os.ModePerm)

This worked for me!

Solution 2:[2]

I have found the cause for why Spring Boot was not autowiring my properties with @Value or @ConfigurationProperties It turns out that the project I am trying to migrate implemented a PropertyPlaceholderConfigurer bean which was failing to initialize the properties properly. I have done away with that bean and the application is now loading and autowiring all properties from application.properties (from all modules)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Boom3k
Solution 2 user236427