404 not found mailgun domain on laravel
Asked Answered
M

3

5

i'm actually struggling with mailgun's on laravel, I'm on laravel 6, i've set up auth and am trying to make the password reset functionnality work. So i decided to use mailgun as email server,

here is my .env file :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:************
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=******
DB_USERNAME=******
DB_PASSWORD=******

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=tls

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

mail.php:

<?php

return [
   'driver' => env('MAIL_DRIVER', 'mailgun'),
   'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
   'port' => env('MAIL_PORT', 587),
   'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Parisworld support'),
    ],
   'encryption' => env('MAIL_ENCRYPTION', 'tls'),
   'username' => env('MAIL_USERNAME'),
   'password' => env('MAIL_PASSWORD'),
   'sendmail' => '/usr/sbin/sendmail -bs',
   'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
   'log_channel' => env('MAIL_LOG_CHANNEL'),
]

And my services.php:

<?php

   return [
    'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN', 'parisworld.ovh'),
        'secret' => env('MAILGUN_SECRET', '********'),
    ],

    'postmark' => [
        'token' => env('POSTMARK_TOKEN'),
    ],

    'ses' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],

];

I don't get what I'm actually missing, i configured the mailgun domain and verified the dns, everything is fine on mailgun side, I could even send myself a mail using the curl method but when I try to reset my password from my app I'm getting this error :

Client error: `POST https://api.mailgun.net/v3/parisworld.ovh/messages.mime` resulted in a `404 NOT FOUND` response: { "message": "Domain not found: parisworld.ovh" } 

I hope this post is clear enought, any idea is welcome :)

Milore answered 30/9, 2019 at 18:32 Comment(0)
L
3
  1. On Mailgun Domains page (ex. https://app.eu.mailgun.com/app/sending/domains) get your domain region;
  2. Check Domain Settings -> DNS records;
  3. Edit .env-file:

.env file

MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mg.docm****.***
MAILGUN_SECRET=d76da6b39e********

# For EU Mailgun domain region
MAILGUN_ENDPOINT=api.eu.mailgun.net

# For US Mailgun domain region
MAILGUN_ENDPOINT=api.mailgun.net

More information about endpoints https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions

Mailgun: Domains page

Mailgun: Domain Settings -> DNS records

Mailgun: Domain Settings -> DNS records 2

Lexis answered 4/2, 2020 at 14:33 Comment(0)
M
2

Well i found the solution of this problem, I created my account in EU, by default when you refer the mailgun api url, smtp.maigun.org corresponds to the US api. So laravel was looking for the domain parisworld.ovh in the US api while it was registered in EU. To work with mailgun's eu api you have to change in .env (in my case):

MAIL_HOST=smtp.mailgun.org

to

MAIL_HOST=smtp.eu.mailgun.org

I don't know why but i still had an authentification problem :

enter image description here

To solve this one, I just had to reset my smtp password from the mailgun interface, paste the new password in my .env and it's now working ! Hope this post will help some :)

Milore answered 1/10, 2019 at 14:39 Comment(0)
B
1

If you are in the EU you need to make sure you set the following in your config/services.php

'mailgun' => [
    'domain' => env('MAILGUN_DOMAIN'),
    'endpoint' => env('MAILGUN_ENDPOINT'),
    'secret' => env('MAILGUN_SECRET'),
],

and then add the following to your .env

MAILGUN_ENDPOINT=api.eu.mailgun.net

and then

php artisan config:cache
Brennabrennan answered 7/5, 2020 at 19:11 Comment(1)
Thanks! I'm in the Netherlands and this works for me!Trifid

© 2022 - 2024 — McMap. All rights reserved.