0

I'm trying to send email to new user so that they can verify their email address first but I'm receiving an exception Which says Authentication required but my credentials are totally correct.

Swift_TransportException

Expected response code 250 but got code "530", with message "530 Authentication required

Exception Error Details

.Env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.elasticemail.com
MAIL_PORT=2525
MAIL_USERNAME=aniket.************
MAIL_PASSWORD=b6762146-*******-*******-******
MAIL_ENCRYPTION=tls


Mail.php

 'driver' => env('MAIL_DRIVER', 'smtp'),

/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/

'host' => env('MAIL_HOST', 'smtp.elasticemail.com'),

/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/

'port' => env('MAIL_PORT', 2525),

/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],

/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/

'encryption' => env('MAIL_ENCRYPTION', 'tls'),

/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/

'username' => env('aniket.************'),

'password' => env('b6762146-********-*********'),

/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/

'sendmail' => '/usr/sbin/sendmail -bs',

This is how I'm Sending Mail

namespace App\Factories;

use App\Models\User;
use App\Repositories\ActivationRepository;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\Message;
public function __construct(ActivationRepository $activationRepo, Mailer $mailer)
{
    $this->activationRepo = $activationRepo;
    $this->mailer = $mailer;
}

public function sendActivationMail($user)
{
    if ($user->activated || !$this->shouldSend($user)) {
        return;
    }

    $token = $this->activationRepo->createActivation($user);

    $link = route('user.activate', $token);
    $message = sprintf('Activate account %s', $link, $link);

    $this->mailer->raw($message, function (Message $m) use ($user) {
        $m->to($user->email)->subject('Activation mail');
    });
}

2 Answers 2

3

Authentication required = Authentication fails..

Make sure in your .env file (or if you use your app.mail) the MAIL_USERNAME is the sender of the email and that MAIL_USERNAME and MAIL_PASSWORD are valid.

The from address in your mail.php should be the same as MAIL_USERNAME

Sign up to request clarification or add additional context in comments.

3 Comments

I would also add that the OP shouldn't change the mail.php config as he clearly did.
yes he should leave this as it is : 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'),
I have configured my domain to send email through elasticmail i have tried sending mail through gmail but no luck, so my email from should be my domain email e.g [email protected]
2

In your .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

In your config/mail.php

 'from' => ['address' => '[email protected]', 'name' => null],

That will do it! :-D

Make sure to turn this on google lesser app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.