Documentation ¶
Overview ¶
Package gmail is a simple Go library for sending emails from a Gmail account.
NB: The attachment code was inspired by scorredoira's email (https://github.com/scorredoira/email) and full credit goes to him.
package main import "github.com/SlyMarbo/gmail" func main() { email := gmail.Compose("Email subject", "Email body") email.From = "username@gmail.com" email.Password = "password" // Defaults to "text/plain; charset=utf-8" if unset. email.ContentType = "text/html; charset=utf-8" // Normally you'll only need one of these, but I thought I'd show both. email.AddRecipient("recipient@example.com") email.AddRecipients("another@example.com", "more@example.com") err := email.Send() if err != nil { // handle error. } }
Note:
If you have problems with authentication, be sure to check your password settings. While developing the package, I had forgotten that I have application-specific passwords enabled on my Google account, so my account password wasn't working; I had to sign into my account and create an application-specific password for the package and use that.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Email ¶
type Email struct {
Subject, Body string
From string
Name string
Password string
ContentType string
To []string
Attachments map[string][]byte
}
Email represents a single message, which may contain attachments.
func Compose ¶
Compose begins a new email, filling the subject and body, and allocating memory for the list of recipients and the attachments.
func (*Email) AddRecipient ¶
AddRecipient adds a single recipient.
func (*Email) AddRecipients ¶
AddRecipients adds one or more recipients.