Este guia descreve como usar a Mail API para enviar e receber e-mails.
Antes de começar
Você precisa registrar seus remetentes de e-mails como remetentes autorizados. Para mais informações, consulte quem pode enviar e-mails.
Como enviar e-mails
A função integrada mail() do PHP pode enviar e-mails por meio da API Mail do App Engine. Isso deve funcionar bem com a maioria dos códigos existentes, desde que esteja em conformidade com as restrições listadas no Envio de e-mails.
Como alternativa, é possível fazer chamadas diretas para a API Mail:
use google\appengine\api\mail\Message;// Notice that $image_content_id is the optional Content-ID header value of the// attachment. Must be enclosed by angle brackets (<>)$image_content_id = '<image-content-id>';// Pull in the raw file data of the image file to attach it to the message.$image_data = file_get_contents('image.jpg');try { $message = new Message(); $message->setSender('from@example.com'); $message->addTo('to@example.com'); $message->setSubject('Example email'); $message->setTextBody('Hello, world!'); $message->addAttachment('image.jpg', $image_data, $image_content_id); $message->send(); echo 'Mail Sent';} catch (InvalidArgumentException $e) { echo 'There was an error';}
Como receber e-mails
É possível configurar seu aplicativo para receber e-mails de endereços no seguinte formato:
anything@appid.appspotmail.com
Para receber e-mails:
Ative os e-mails recebidos no arquivo app.yaml do seu aplicativo. Adicione o seguinte a inbound_services:
-mail
No arquivo de configuração, crie mapeamentos de caminhos de URL que representem endereços de e-mail para gerenciadores no código do aplicativo. O padrão /_ah/mail/.+ corresponde a todos os endereços de recebimento de e-mail:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-03-06 UTC."],[[["This guide outlines how to utilize the Mail API for sending and receiving emails within the context of App Engine, particularly for first-generation runtimes."],["PHP's built-in `mail()` function can send emails using the App Engine Mail API, and direct calls to the API are also possible using the `google\\appengine\\api\\mail\\Message` class."],["Before sending emails, you must register your sender email addresses as authorized senders, according to the Mail API's guidelines."],["To receive emails, enable incoming mail in your `app.yaml` file, create URL mappings for incoming email addresses, and implement handlers in your app's code to process the received mail using the Mailparse extension."],["Your app can receive incoming emails at addresses formatted as `anything@appid.appspotmail.com`, even if your app is deployed on a custom domain, as you cannot use custom domain addresses to receive emails."]]],[]]