As another answer option from Gabriel, I would recommend using the go App Engine environment to send and receive mail with the mail API .
From the doc:
Receiving mail
Your application can receive emails at the addresses of the following form:
anything@appid.appspotmail.com
Compare with the configuration of incoming mail processing in python , as discussed here , including incoming mail in your app.yaml application app.yaml quite simple:
inbound_services: - mail
Name your application file as mail.go , then register the handler on the path /_ah/mail/ and read the email data from *http.Requestlike using net/mail :
func incomingMail(w http.ResponseWriter, r *http.Request) { ctx := appengine.NewContext(r) defer r.Body.Close() var b bytes.Buffer if _, err := b.ReadFrom(r.Body); err != nil { log.Errorf(ctx, "Error reading body: %v", err) return } log.Infof(ctx, "Received mail: %v", b) }
Sending mail
Follow this guideline to register sender emails as authorized senders
Use the mail.Message type to set the sender, recipient, subject and body of the message.
Send an email using the mail.Send function.
func confirm(w http.ResponseWriter, r *http.Request) { ctx := appengine.NewContext(r) addr := r.FormValue("email") url := createConfirmationURL(r) msg := &mail.Message{ Sender: "Example.com Support < support@example.com >", To: []string{addr}, Subject: "Confirm your registration", Body: fmt.Sprintf(confirmMessage, url), } if err := mail.Send(ctx, msg); err != nil { log.Errorf(ctx, "Couldn't send email: %v", err) } }
Expand
A complete sample code for receiving and sending is available here on GitHub:
GoogleCloudPlatform / golang-samples / docs / appengine / mail / mail.go
To clone the sample code, go to Console . Click the button to open Cloud Shell :
then similarly this quick start enter the following steps:
$ SOURCEDIR=https://github.com/GoogleCloudPlatform/golang-samples.git $ TUTORIALDIR=~/src/your-application-id/go_gae_samples $ git clone $SOURCEDIR $TUTORIALDIR $ cd $TUTORIALDIR $ git checkout master $ cat docs/appengine/mail/app.yaml $ cat docs/appengine/mail/mail.go $ goapp serve docs/appengine/mail/app.yaml
Here you can access the application on port 8080 using Web preview
.
To complete, press Ctrl+C in Cloud Shell .
Finally, you can deploy your application
goapp deploy -application your-application-id -version 0
Click url to view it
http:
Then send an email to anything@your-application-id.appspotmail.com if it works.