mailjet / laravel-mailjet

Laravel package for Mailjet API V3 and Laravel Mailjet Mail Transport
MIT License
94 stars 93 forks source link

Emails aren't being sent when used with simple Auth #36

Closed i-fail closed 4 years ago

i-fail commented 4 years ago

Description:

Emails aren't sent on Auth user registration / verification

Steps To Reproduce:

I did all of the things below:

// User authentication routes Auth::routes(['verify' => true]);

// MustVerifyEmail interface class User extends Authenticatable implements MustVerifyEmail

Entered all the credentials into .env

MAIL_MAILER=mailjet
MAIL_DRIVER=mailjet
MAILJET_APIKEY=3acaf7...
MAILJET_APISECRET=34974...

Entered the transport string into config\mail.php

'default' => env('MAIL_MAILER', 'mailjet'),
'mailers' => [
    'mailjet' => [
        'transport' => 'mailjet',
    ],

Added config/services.php

'mailjet' => [
        'key' => env('MAILJET_APIKEY'),
        'secret' => env('MAILJET_APISECRET'),
        'transactional' => [
            'call' => true,
            'options' => [
                'url' => 'api.mailjet.com',
                'version' => 'v3.1',
                'call' => true,
                'secured' => true
            ]
        ],
        'common' => [
            'call' => true,
            'options' => [
                'url' => 'api.mailjet.com',
                'version' => 'v3',
                'call' => true,
                'secured' => true
            ]
        ]
]

Added providers to config/app.php

// Mailjet
Mailjet\LaravelMailjet\MailjetServiceProvider::class,
Mailjet\LaravelMailjet\MailjetMailServiceProvider::class,

Yet when I go through the user registration process, email is not sent. No error of any kind. Just not sent.

Same if I navigate to /email/verify, and click on "click here to request another", no emails are sent. Just silent 302, no errors.

Here's proof that Auth::routes work fine, everything works fine. Except emails aren't being sent.

https://www.youtube.com/watch?v=eMDy4ZSu2jY

When I manually call MailJet API with the same credentials, emails go out perfectly fine. It's just UI / Auth is not calling MailJet API.

I tried the same with simple SMTP instead of MailJet, same problem. Emails not sent.

i-fail commented 4 years ago

I finally tracked the source of the problem. Your installation instructions are incomplete with one small, but very important step missing:

in config/mail.php you also have to change these two lines:

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

What happened is, MJ API would try to email with the "from" address of hello@example.com, MJ would respond with an error, and not send the email out. Because hello@example.com is not validated.

The only reason I found this out was that because the MJ account owner started receiving strange emails that said

We are contacting you as you (or one of your team members) tried to send an
email with sender address: hello@example.com. But this sender address has not
been validated yet on your account: ..."

Maybe you should add a sanity check and error_log this.

uavn commented 4 years ago

@i-fail Thanks, I updated readme file with two more settings: MAIL_FROM_ADDRESS=YOUR_EMAIL_FROM_ADDRESS MAIL_FROM_NAME=YOU_FROM_NAME

in which you can set your email and name, instead of setting them in config/mail.php, because env('MAIL_FROM_ADDRESS', 'hello@example.com') and env('MAIL_FROM_NAME', 'Example') will look first for the MAIL_FROM_ADDRESS or MAIL_FROM_NAME in .env file, and then if they are not set - it will use default values, which in your case are 'hello@example.com' and 'Example'.