Search code examples
laravel-5mailgun

laravel 5.2 and mailgun


This should be something really simple but all the tutorials are too old and I really don't know what half of these things are:

In config/mail.ph

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',

So in my .env file I have:

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=(Default SMTP Login <- found in mailgun)
MAIL_PASSWORD=(Default Password <- found in mailgun)

I beleive these are all good. Next in config/services.php I have

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

And further in my .env file:

MAILGUN_DOMAIN=(API Base URL <- found in mailgun)
MAILGUN_SECRET=(API Key <- found in mailgun)

but when I run the artisan queue:listen I get error:

Client error: `POST https://api.mailgun.net/v3/-API Base URL-/messages.mime` resulted in a `404 NOT FOUND` response. 

where -API Base URL- is the value of the MAILGUN_DOMAIN variable in my .env file

I tried putting my domain name mail.mydomain.com in the MAILGUN_DOMAIN but then I got the message to activate my account although the account was already verified and hence, I believe, active.

I tried leaving the MAILGUN_DOMAIN empty and then I got the

`POST https://api.mailgun.net/v3//messages.mime` resulted in a `404 NOT FOUND` 

So, my conclusion is there should be something between ...v3/ and /messages.mime but I can't figure out what.

EDIT:

I found this:

https://laracasts.com/discuss/channels/laravel/laravel-and-mailgun-1

and it seems i can remove the MAIL_USERNAME and MAIL_PASSWORD but I don't know where to find this sandboxxxxxxxx code.


Solution

  • The right thing to enter is your domain name that you set up in mailgun. In my case it was mail.mydomain.com.

    However, I never bothered to activate the account (you need to give them your phone number so that's most likely the reason I skipped it) so I was getting this message. Problem is solved now.