Go 1.11 has reached end of support
and will be deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Go 1.11
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Go
1.11 applications will continue to run and receive traffic after their
deprecation date. We
recommend that you migrate to the latest supported version of Go.
Stay organized with collections
Save and categorize content based on your preferences.
This guide describes how to use the Mail API to send and receive mail.
Before you begin
You must register your sender emails as authorized senders. For more
information, see
who can send email.
Sending mail
To send mail from your application:
Use the mail.Message type to set the sender, recipient, subject, and body
of the message.
Send the email with the mail.Send function.
The following example sends an email message to the user as a confirmation that
they have created a new account with the application:
import("bytes""fmt""net/http""google.golang.org/appengine""google.golang.org/appengine/log""google.golang.org/appengine/mail")funcconfirm(whttp.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),}iferr:=mail.Send(ctx,msg);err!=nil{log.Errorf(ctx,"Couldn't send email: %v",err)}}constconfirmMessage=`Thank you for creating an account!Please confirm your email address by clicking on the link below:%s`
Receiving mail
You can set up your app to receive incoming email at addresses in the following
format:
anything@appid.appspotmail.com
To receive email:
Enable incoming mail in your app's app.yaml file:
inbound_services:-mail
Set up a handler to process incoming emails, which are supplied to your app
as MIME data in an HTTP POST request.
In your app, register a handler to the /_ah/mail/ path:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis guide provides instructions on how to utilize the Mail API for sending and receiving emails in first-generation runtimes, with guidance for migration options if updating to App Engine Go 1.12+.\u003c/p\u003e\n"],["\u003cp\u003eSending mail involves using the \u003ccode\u003email.Message\u003c/code\u003e type to define the email's details and the \u003ccode\u003email.Send\u003c/code\u003e function to dispatch the message, as demonstrated with a confirmation email example.\u003c/p\u003e\n"],["\u003cp\u003eTo receive mail, you must enable incoming mail services in the \u003ccode\u003eapp.yaml\u003c/code\u003e file and set up a handler to process emails delivered as MIME data via HTTP \u003ccode\u003ePOST\u003c/code\u003e requests to the \u003ccode\u003e/_ah/mail/\u003c/code\u003e path.\u003c/p\u003e\n"],["\u003cp\u003eBefore sending any mail, all sender email addresses must be registered as authorized senders.\u003c/p\u003e\n"],["\u003cp\u003eReceiving email is only possible to addresses formatted as \u003ccode\u003eanything@appid.appspotmail.com\u003c/code\u003e, and this is independent of whether or not the app is on a custom domain.\u003c/p\u003e\n"]]],[],null,["# Sending and Receiving Mail with the Mail API\n\nThis guide describes how to use the Mail API to send and receive mail.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| go\n| /services/access). If you are updating to the App Engine Go 1.12+ runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/go-differences) to learn about your migration options for legacy bundled services.\n\nBefore you begin\n----------------\n\nYou must register your sender emails as authorized senders. For more\ninformation, see\n[who can send email](/appengine/docs/legacy/standard/python/mail#who_can_send_mail).\n\nSending mail\n------------\n\nTo send mail from your application:\n\n1. Use the `mail.Message` type to set the sender, recipient, subject, and body\n of the message.\n\n2. Send the email with the `mail.Send` function.\n\nThe following example sends an email message to the user as a confirmation that\nthey have created a new account with the application: \n\n import (\n \t\"bytes\"\n \t\"fmt\"\n \t\"net/http\"\n\n \t\"google.golang.org/appengine\"\n \t\"google.golang.org/appengine/log\"\n \t\"google.golang.org/appengine/mail\"\n )\n\n func confirm(w http.ResponseWriter, r *http.Request) {\n \tctx := appengine.NewContext(r)\n \taddr := r.FormValue(\"email\")\n \turl := createConfirmationURL(r)\n \tmsg := &mail.Message{\n \t\tSender: \"Example.com Support \u003csupport@example.com\u003e\",\n \t\tTo: []string{addr},\n \t\tSubject: \"Confirm your registration\",\n \t\tBody: fmt.Sprintf(confirmMessage, url),\n \t}\n \tif err := mail.https://cloud.google.com/appengine/docs/legacy/standard/go111/reference/latest/mail.html#google_golang_org_appengine_mail_Send(ctx, msg); err != nil {\n \t\tlog.https://cloud.google.com/appengine/docs/legacy/standard/go111/reference/latest/log.html#google_golang_org_appengine_log_Errorf(ctx, \"Couldn't send email: %v\", err)\n \t}\n }\n\n const confirmMessage = `\n Thank you for creating an account!\n Please confirm your email address by clicking on the link below:\n\n %s\n `\n\nReceiving mail\n--------------\n\nYou can set up your app to receive incoming email at addresses in the following\nformat: \n\n anything@appid.appspotmail.com\n\n| **Note:** Even if your app is deployed on a custom domain, you can't receive email sent to addresses in that domain.\n\nTo receive email:\n\n1. Enable incoming mail in your app's `app.yaml` file:\n\n inbound_services:\n - mail\n\n2. Set up a handler to process incoming emails, which are supplied to your app\n as MIME data in an HTTP `POST` request.\n\n 1. In your app, register a handler to the `/_ah/mail/` path:\n\n func init() {\n \thttp.HandleFunc(\"/_ah/mail/\", incomingMail)\n }\n\n 2. In the handler, read the email's data from the `*http.Request`:\n\n func incomingMail(w http.ResponseWriter, r *http.Request) {\n \tctx := appengine.NewContext(r)\n \tdefer r.Body.Close()\n \tvar b bytes.Buffer\n \tif _, err := b.ReadFrom(r.Body); err != nil {\n \t\tlog.Errorf(ctx, \"Error reading body: %v\", err)\n \t\treturn\n \t}\n \tlog.Infof(ctx, \"Received mail: %v\", b)\n }\n\n You can use the [`net/mail`](http://golang.org/pkg/net/mail/) package in the\n standard library to parse mail messages."]]