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 https://support.google.com/mail/?p=WantAuthError h9-20020a05600c314900b003d99469ece1sm6804459wmo.24 - gsmtp
After Googling around, I found out that this is an authentication problem. See https://bobcares.com/blog/smtp-error-530/
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