ProxiedMail provides an API to create email address and receive any incoming messages straight to your application within the simple composer package.
Here in this example you can see how to receive sent email to your API. The program will print email address created to receive your email message.
PROXY-EMAIL: 4bd6c97b9@proxiedmail.com Webhook STATUS: Received: no
Then, just send the email to the printed address. When app receive your message, it will print the following:
PROXY-EMAIL: 4bd6c97b9@proxiedmail.com Webhook STATUS: Received: yes WEBHOOK PAYLOAD: { "id":"EB442408-D500-0000-00003CC8", "payload":{ "Content-Type":"multipart\/alternative; boundary=\"000000000000714564060f56f6c2\"", "Date":"Sat, 20 Jan 2024 02:00:25 +0000", "Dkim-Signature":"DKIM", "From":"Alex Yatsenko", "Message-Id":" ", "Mime-Version":"1.0", "Subject":"hey mate", "To":"4bd6c97b9@proxiedmail.com", "X-Envelope-From":"sender@gmail.com", "X-Mailgun-Incoming":"Yes", "X-Received":"Received details", "body-html":" hey hey<\/div>\r\n", "body-plain":"hey hey\r\n", "domain":"proxiedmail.com", "from":"Alex Alex", "message-headers":"HEADERS JSON....", "recipient":"4bd6c97b9@proxiedmail.com", "sender":"sender@gmail.com", "signature":"....", "stripped-html":" hey hey<\/div>\n", "stripped-text":"hey hey", "subject":"hey mate", "timestamp":"1705716046", "token":"..." }, "attachments":[ ], "recipient":{ "address":"4bd6c97b9@proxiedmail.com" }, "receivedAt":"Sat Jan 20 2024 02:00:46 GMT+0000", "user":{ "id":"1B3AAA43-11-0000-cc", "username":"username+t1@gmail.com", "token":"Bearer ...." } }
The code to execute is the following
<?php | |
use ProxiedMail\Client\Config\Config; | |
use ProxiedMail\Client\Entities\ResponseEntity\OauthAccessTokenEntity; | |
use ProxiedMail\Client\Entrypoint\PxdMailApinitializer; | |
use ProxiedMail\Client\Facades\ApiFacade; | |
require 'vendor/autoload.php'; | |
// put here your ProxiedMail credentials | |
$email = 'example@example.com'; | |
$pass = '1'; | |
/** | |
* @var ApiFacade $facade | |
*/ | |
$facade = PxdMailApinitializer::init(); | |
/** | |
* @var OauthAccessTokenEntity $r | |
*/ | |
$r = $facade->login($email, $pass); | |
//settings bearer token | |
$config = (new Config())->setBearerToken('Bearer ' . $r->getBearerToken()); | |
$facade = PxdMailApinitializer::init($config); | |
//receiving API token by bearer token | |
$apiToken = $facade->getApiToken(); | |
$config = new Config(); | |
//setting API token | |
$config->setApiToken($apiToken->getApiToken()); | |
$api = PxdMailApinitializer::init($config); | |
$proxyEmail = $api->createProxyEmail( | |
[], | |
null, | |
null, | |
null, | |
true | |
); | |
// while (true) with 100 seconds limit | |
foreach(range(0, 180) as $non) { | |
echo "PROXY-EMAIL: " . $proxyEmail->getProxyAddress() . "\n"; | |
echo "Time limit is 3 mins \n"; | |
echo "Send the email to this proxy-email to get email payload printed here \n"; | |
//checking webhook receiver | |
$receivedEmails = $api->getReceivedEmailsLinksByProxyEmailId($proxyEmail->getId())->getReceivedEmailLinks(); | |
echo "Amount of received emails: " . count($receivedEmails) . "\n"; | |
foreach ($receivedEmails as $receivedEmail) { | |
echo "Have received email: \n"; | |
var_dump($receivedEmail); //you can also receive a payload here. Check out attributes | |
echo "\n"; | |
} | |
echo "\n"; | |
sleep(1); | |
} |
To run the example above just create folder, install lib there via composer and put it to the file (t.php), then run:
php t.php
Please see more on GitHub or docs
Start receiving emails via webhooks/callbacks to your system. We will send you all information about your email including attachments and headers.
Receive webhooks on emails sent to your custom domain if you able to set up MX records for it.
Check out our documentation to know how to build your app in a proper way.