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`
接收邮件
您可以对应用进行设置,通过如下格式的地址接收传入电子邮件:
anything@appid.appspotmail.com
如需接收电子邮件,请执行以下操作:
在应用的 app.yaml 文件中启用接收邮件。
inbound_services:-mail
设置处理程序以处理传入的电子邮件,这些电子邮件作为 HTTP POST 请求中的 MIME 数据提供给您的应用。