Panduan ini menjelaskan cara menggunakan Mail API untuk mengirim dan menerima email.
Sebelum memulai
Anda harus mendaftarkan email pengirim sebagai pengirim yang sah. Untuk mengetahui informasi selengkapnya, lihat siapa yang dapat mengirim email.
Mengirim email
Fungsi mail() bawaan PHP dapat mengirim email melalui App Engine Mail API. Ini akan berfungsi baik dengan
sebagian besar kode yang ada selama sesuai dengan batasan yang tercantum dalam
Mengirim email.
Atau, Anda dapat melakukan panggilan langsung ke Mail API:
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';}
Menerima email
Anda dapat menyiapkan aplikasi untuk menerima email masuk di alamat dalam format berikut:
anything@appid.appspotmail.com
Untuk menerima email:
Aktifkan email masuk di file app.yaml aplikasi Anda. Tambahkan kode berikut ke
inbound_services.
-mail
Di file konfigurasi, buat pemetaan dari jalur URL yang mewakili
alamat email ke pengendali dalam kode aplikasi Anda. Pola /_ah/mail/.+
cocok dengan semua alamat email masuk:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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."]]],[]]