February 2019
Intermediate to advanced
450 pages
11h 59m
English
To send a message, we have to package up the data in a raw format to send through the API. We'll re-use the ToGMailEncoding() function from the Post example in Chapter 12, Concurrency, Networking, and Cloud Services. Before encoding the email, we set an appropriate "From" email address (be sure to use the email address of the account you are signed in with or a registered alias) and the current date for the time of sending. After encoding, we set the data to the Raw field of a gmail.Message type and pass it to the Gmail Send() function:
func (g *gMailServer) Send(email *EmailMessage) { email.From = "YOUR EMAIL ADDRESS" email.Date = time.Now() data := email.ToGMailEncoding() msg := &gmail.Message{Raw:data} srv.Users.Messages.Send( ...
Read now
Unlock full access