Skip to content

Instantly share code, notes, and snippets.

@yatsenkolesh
Created February 25, 2024 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yatsenkolesh/624dd24ed12e926b07dfb924ac62957e to your computer and use it in GitHub Desktop.
Save yatsenkolesh/624dd24ed12e926b07dfb924ac62957e to your computer and use it in GitHub Desktop.
<?php
use ProxiedMail\Client\Bridge\ProxiedMailClient;
use ProxiedMail\Client\Facades\ApiFacade;
class ExampleController
{
public function browseReceivedEmails(ProxiedMailClient $proxiedMailClient)
{
/**
* @var ApiFacade $api
*/
$api = $proxiedMailClient->getClient();
$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);
echo "\n";
}
echo "\n";
sleep(1);
}
}
public function receiveEmailViaWebhook(ProxiedMailClient $proxiedMailClient)
{
/**
* @var ApiFacade $api
*/
$api = $proxiedMailClient->getClient();
$wh = $api->createWebhook(); //creating webhook-receiver
$proxyEmail = $api->createProxyEmail(
[],
null,
$wh->getCallUrl() //specifying webhook url
);
// while (true) with 100 seconds limit
foreach (range(0, 100) as $non) {
echo "PROXY-EMAIL: " . $proxyEmail->getProxyAddress() . "\n";
echo "Send the email to this proxy-email to get email payload printed here";
//checking webhook receiver
$whStatus = $api->statusWebhook($wh->getId());
echo "Webhook STATUS: \n";
echo "Received: " . ($whStatus->isReceived() ? 'yes' : 'no') . "\n"; //printing webhook status
//printing payload if received
if ($whStatus->isReceived()) {
echo "WEBHOOK PAYLOAD: \n";
echo json_encode($whStatus->getPayload());
break;
}
echo "\n";
sleep(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment