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-03-05 UTC."],[[["This 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+."],["Sending mail involves using the `mail.Message` type to define the email's details and the `mail.Send` function to dispatch the message, as demonstrated with a confirmation email example."],["To receive mail, you must enable incoming mail services in the `app.yaml` file and set up a handler to process emails delivered as MIME data via HTTP `POST` requests to the `/_ah/mail/` path."],["Before sending any mail, all sender email addresses must be registered as authorized senders."],["Receiving email is only possible to addresses formatted as `anything@appid.appspotmail.com`, and this is independent of whether or not the app is on a custom domain."]]],[]]