Search code examples
laravelmailgunlaravel-mail

How can i filter bounces mail with date and time? [mailgun, laravel]


i am currently using mailgun api /bounces and i got bounces emails but it have all bounces emails no filter. But actually i want only last 1 hours bounces emails. How can i get like this?

Currently i am using

$response = Http::get('https://api:'
                    . env('MAILGUN_SECRET')
                    . '@api.mailgun.net/v3/'
                    . env('MAILGUN_DOMAIN')
                    . '/bounces');

I checked mailgun documentation. I didn't get any solution. Anyone help me to find out solution. Thanks.


Solution

  • Actually bounces api have list of bounces email so we can't filter for that. so if we want to filter then we use events api like below for above scenario.

            $end = Carbon::now()->toRfc2822String();
            $begin = Carbon::now()->subHour()->toRfc2822String();
            
            $response = Http::get('https://api:'
                                . env('MAILGUN_SECRET')
                                . '@api.mailgun.net/v3/'
                                . env('MAILGUN_DOMAIN')
                                . '/events', [
                                    'event' => 'failed',
                                    'begin' => $begin,
                                    'end' => $end,
                                    'ascending' => 'yes'
                                ]);
    

    This way i solved my problem. I didn't get any answer for this question so that i add my answer it will help someone when face same issue. Thanks.