Hi all,
In my local (!) CakePHP 4 installation, I want to send emails via the Gmail SMTP server. Unfortunately, I constaltly have the same error when I try to send an email:
SMTP Error: 530 5.7.0 Check Gmail through other email platforms - Gmail Help h9-20020a05600c314900b003d99469ece1sm6804459wmo.24 - gsmtp
After Googling around, I found out that this is an authentication problem. See SMTP error 530: Authentication Required - Let's fix it!!
Back in time (in my CakePHP2 installation) I used the āLess secure appsā from Google and that always worked great. But since May 2022, it is no longer supported by Google. Nowadays, we should use āApp passwordsā and that was exactly what I did:
As you can see in this screenshot (sorry, itās in Dutch), I selected the option āOther (custom name)ā. Then, I copied the given password into notepad.
(Little note: the CakePHP 4 cookbook is outdated, it still tells us to use āLess secure appsā, see Mailer - 4.x)
Then, I created a new Mailer in ArticlesController.php:
$mailer = new Mailer('sabasco');
$mailer->setEmailFormat('html')
->setSubject(__('Comment on article'))
->setReplyTo($comment->email, $comment->name)
->setViewVars([
'id' => $comment->id,
'name' => $comment->name,
'email' => $comment->email,
'content' => nl2br($comment->content),
'articleId' => $comment->articleId,
'articleName' => $article->name
])
->viewBuilder()
->setLayout('default')
->setTemplate('comment');
$mailer->deliver();
Then, I configured my app.php like this:
'EmailTransport' => [
'gmail' => [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'sabasco.development@gmail.com',
'password' => '16DigitsPasswordFromNotepad',
'className' => 'Smtp',
'tls' => true
]
],
'Email' => [
'sabasco' => [
'transport' => 'gmail',
'to' => ['hello@myemailaddress.be' => 'Sabasco'],
'from' => ['hello@myemailaddress.be' => 'Sabasco']
]
],
So this setup doesnāt work and I totally donāt understand why. I also tried to change the EmailTransport in many ways, like this:
'EmailTransport' => [
'gmail' => [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'sabasco.development@gmail.com',
'password' => '16DigitsPasswordFromNotepad',
'client' => null,
'className' => 'Smtp',
'tls' => true,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
]
],
or like this:
'EmailTransport' => [
'gmail' => [
'host' => 'ssl://smtp.gmail.com',
'port' => 587,
'username' => 'sabasco.development@gmail.com',
'password' => '16DigitsPasswordFromNotepad',
'client' => null,
'className' => 'Smtp',
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
],
],
I also tried to change the port to 25 or 465, but I always got the same SMTP 530-error
Some other developers had issues with an antivirus program. Iām using Bitdefender, but I donāt find any options where I can disable some mail related options. So I donāt think it has something to do with my problem.
Iāve been struggeling around many hours with this issue and I reached the point where I have no other options to call for your help
Does anybody have a clue what Iām doing wrong?
Many many thanks for your support!
I hope my question and your answer can help other developers too <3