Receive inbound email with Laravel

https://opengraph.githubassets.com/2305774d1659683786b6e15037504edf7c06cfafa867d39ae79ad7ef401b55f1/proxied-mail/laravel-receive-email

ProxiedMail Client | Receive email via webhook Laravel

ProxiedMail 👷‍♀️ is a simple package for the base library to create proxy emails and receive webhooks or simply browse email list.
You can find the base PHP library at https://github.com/proxied-mail/proxiedmail-php-client

You’re welcome to visit the docs.

ProxiedMail is a tool that brings the email experience to a new level because it was built around the privacy first concept that enhances using a unique email each time which makes it a second password, but also allows you more control over your correspondence.
Additionally, it gives you the advantage of moving to another email provider just in a few seconds.
Because we have this kind of system we also aim to bring more into the experience of development using emails.

đź›  Creating endless proxy emails with one of ProxiedMail domains (i.e abc@proxiedmail.com, abcd@pxdmail.com, abcde@pxdmail.net)

đź›  Setting up forwarding email or disabling forwarding

đź›  Setting up a callback to your URL

đź›  Browsing received emails on the received emails endpoint

đź›  Setting up custom domains. You can do everything using your domain as well.

đź›  Domain-to-domain forwarding. Just in case you need it we can forward emails by mask, like *@domainhostedatproxiedmail.com -> *someotherdomain.com. In this case, the MX of the first domain should be pointed to ProxiedMail and the second domain should be verified by TXT record.

Via composer

$ composer require proxiedmail/laravel-receive-email

This package provide auto-discovery for service provider

If Laravel package auto-discovery is disabled, add service providers manually to /config/app.php. There are service provider you must add:

\ProxiedMail\Client\Providers\ProxiedMailServiceProvider::class

Publish client configuration:

php artisan vendor:publish --tag=proxiedmail

Configure ProxiedMail client:

Put your ProxiedMail API token in /config/proxiedmail.php. You can find this token in ProxiedMail API Settings.

return [
    'apiToken' => 'YOUR API TOKEN',
    'host' => 'https://proxiedmail.com',
];

This example demonstrates create proxy emails, browse received emails and receive emails via webhook.

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);
        }
    }
}

You can create find the UI on ProxiedMail to manage your domains, emails, and webhooks.

Please feel free to fork and sending Pull Requests. This project follows Semantic Versioning 2 and PSR-2.

GPL3. Please see License File for more information.

For any questions please contact laraclient@pxdmail.com

Also please check out the article how to receive emails in Laravel in our blog.
If you’re interested in receiving emails in PHP use the library for pure PHP.

Article: how to receive emails in PHP

Laravel News Links

How to Tie a Lasso

https://content.artofmanliness.com/uploads/2024/08/Tie-a-Lasso-2.jpg

What man hasn’t imagined what it would be like to be a cowboy on the open range?

And when you think about being a cowboy, you probably imagine yourself swinging a lasso above your head to round up wayward dogies

The lasso, or lariat, that we know today originated with Mexican vaqueros back in the 18th and 19th centuries. In the fluid social world of the American West, American cowboys picked up the lasso from their Mexican counterparts to aid them in their own cow punching.

North America isn’t the only place where the lasso has been used. Ancient Egyptians and Mongolians used lassos to herd animals, and ancient Persian warriors employed them in battle.

Yes, the lasso is indeed a manly implement. And today we’re going to show you how to tie one.

At the heart of every lasso is the honda knot. It’s a knot that creates a small, secure loop through which you pass the rope in order to create a large loop that can be tightened and loosened easily.

The rope you use for lassos needs to be a bit stiff so that the loop maintains its shape when you throw it. Traditionally, lassos were made with stiff rawhide or manila rope (check out our article on rope material!). Today, cowboys use nylon or polyester ropes which offer great durability.

Follow our illustrated guide and soon you’ll be ready to hit the Lonesome Dove trail with Gus and Woodrow.

Help support independent publishing. Make a donation to The Art of Manliness! Thanks for the support!

The Art of Manliness

Block Known Spam IPs from Your Laravel App with the Abuse IP Package

https://picperf.io/https://laravelnews.s3.amazonaws.com/featured-images/laravel-abuse-ip-featured.png

Block Known Spam IPs from Your Laravel App with the Abuse IP Package

The Laravel Abuse IP community package by Rahul Alam adds a layer of protection to your Laravel application from known spam IPs. This package provides an Artisan command to keep your IP list in sync with the Aggregated AbuseIPDB blocklist and middleware to check requests against the list.

To start using this package, you need sync the blocklist file of IPs. If you run your application on multiple servers, your storage drive will need to be centralized, or you’ll need to sync and store the IP list data on each server.

Next, the package’s AbuseIp middleware will check requests against the block list to prevent IPs on the list from accessing your application. To configure this middleware, you can add it to your Laravel project’s bootstrap/app.php file or add it to routes directly as desired:

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\App\Http\Middleware\AbuseIp::class);
});

// Or via an individual route (or group of routes)
Route::middleware(AbuseIp::class)->get('/', function () {
    return view('welcome');
});

The AbuseIPDB list is updated multiple times a day, so you’ll also want to schedule an update to the blocklist (which is then cached) to run daily:

$schedule->command('abuseip:update')->daily();

You are free to update the source of the IP blocklist via the package’s configuration. You can learn more about this package, get full installation instructions, and view the source code on GitHub.


The post Block Known Spam IPs from Your Laravel App with the Abuse IP Package appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest
Laravel articles like this directly in your inbox.

Laravel News

DIY PVC Slingbow

https://theawesomer.com/photos/2024/08/diy_pvc_slingbow_t.jpgMaker Lis X has created some interesting weapons using unconventional materials. He used PVC tubing to build the frame for this unique slingbow and provided step-by-step directions so you can make your own. It’s designed to fire arrows and has a sturdy handgrip underneath for stability and aiming accuracy. Here’s another video showing it in […]The Awesomer

Rebel Ridge (Trailer)

https://theawesomer.com/photos/2024/08/rebel_ridge_trailer_t.jpg(PG-13: Language) A man on his way to post bail for his cousin is assaulted and robbed by the local police themselves. Unfortunately for the crooked cops, their “victim” is a former Marine, and they’re about to reenact Rambo. Writer and director Jeremy Saulnier may have cooked a sleeper in this thrilling action flick. Premieres […]The Awesomer

Request fingerprints and how to use them in Laravel

https://www.amitmerchant.com/cdn/request-fingerprinting-and-how-to-use-it-in-laravel.png

A fingerprint, in general, refers to a unique pattern or characteristic that can be used to identify an individual or an object. This concept is widely used in various fields.

For instance, to uniquely identify a human, the unique patterns of ridges and valleys found on the surface of human fingers or DNA sequences are used.

Similarly, in web applications, the unique patterns of the HTTP requests made by a user can be used to uniquely identify them.

A request fingerprint can be formed by hashing various values of the request, such as the URL, IP address, user agent, and other parameters. The hashed values can then be used to identify the web request.

This can be useful in various scenarios, such as:

  • Tracking: Track individual requests for debugging or monitoring purposes.
  • Logging: Enhance logging by including unique request identifiers, making it easier to trace specific requests in logs.
  • Caching: Create unique cache entries for requests, preventing conflicts and ensuring that the correct data is served for each unique request.
  • Debugging: Identify and debug specific requests more efficiently.

So, let’s learn about you can use fingerprints in Laravel.

Request fingerprinting in Laravel

Laravel comes with a built-in but undocumented method called fingerprint that can be used to generate a unique identifier for a request.

$fingerprint = request()->fingerprint();

// cf3fcc20ae756f4d5a3e1f48a91e722ed93345ca

Here’s what the definition of the fingerprint method in Laravel’s source code looks like.

/**
* Get a unique fingerprint for the request / route / IP address.
*
* @return string
*
* @throws \RuntimeException
*/
public function fingerprint()
{
    if (! $route = $this->route()) {
        throw new RuntimeException('Unable to generate fingerprint. Route unavailable.');
    }

    return sha1(implode('|', array_merge(
        $route->methods(),
        [$route->getDomain(), $route->uri(), $this->ip()]
    )));
}

As you can tell, the method uses things like the request’s IP address, the route’s domain, and the route’s URI to generate a unique identifier for the request. So, the fingerprint for a request will be unique for each request, regardless of the parameters or headers sent with the request.

Usage of the request fingerprints

The generated fingerprint can be used as a part of your cache key to ensure unique cache entries per request should you wish to cache the response.

$fingerprint = request()->fingerprint();

$cacheKey = 'response_' . $fingerprint;
$response = Cache::remember($cacheKey, 60, function () {
    // Generate the response
});

Apart from this, the fingerprint can also be used for logging, debugging, and tracking purposes. For instance, you can use it as a part of the log message to identify the request uniquely.

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
    public function report(Throwable $exception)
    {
        $fingerprint = request()->fingerprint();
        \Log::error('Exception occurred', [
            'fingerprint' => $fingerprint,
            'exception' => $exception
        ]);
        
        parent::report($exception);
    }
}

Here’s how a log message generated by the above code looks like.

[2024-07-20 12:34:56] local.INFO: Request Fingerprint: 123e4567-e89b-12d3-a456-426614174000 {"url":"http://example.com/api/resource"}
[2024-07-20 12:34:57] local.INFO: Handling request in index method {"fingerprint":"123e4567-e89b-12d3-a456-426614174000"}
[2024-07-20 12:34:58] local.ERROR: Exception occurred {"fingerprint":"123e4567-e89b-12d3-a456-426614174000","exception":"[object] (Exception(code: 0): Example exception at /path/to/file.php:123)"} 

In closing

Incorporating request fingerprints in Laravel enhances debugging and request management by providing unique identifiers for each request.

This enables easy traceability, isolation of issues, and detailed context for debugging. By generating and logging these fingerprints, you can efficiently track and debug requests, improving the overall reliability and maintainability of your application.

Laravel News Links