Email configuration with auth returns SMTP Error: data not accepted

Hi :slight_smile:

I try to setup a contact formular with authentication. For this, I defined a contact.php with the following code:

$kirby->email([
                'template' => 'email',
                'from'     => 'contactform@xxxxxxxxxx.com',
                'replyTo'  => $data['email'],
                'to'       => 'info@xxxxxxxxxxx.de',
                'subject'  => esc($data['name']) . ' sent you a message from your contact form',
                'data'     => [
                    'occupation'  => esc($data['occupation']),
                    'salutation'  => esc($data['salutation']),
                    'name'        => esc($data['name']),
                    'surname'     => esc($data['surname']),
                    'email'      => esc($data['email']),
                    'company'     => esc($data['company']),
                    'text'        => esc($data['text'])
                ]
            ]);

And for the authentication, I added the following to the config.php:

'email' => [
'transport' => [
  'type' => 'smtp',
  'host' => 'smtp.xxxxxxxx.com',
  'port' => 587,
  'security' => true,
  'auth' => true,
  'username' => 'contactform@xxxxxxxxxxxx.de',
  'password' => 'XXXXXXXX',
]

],

But when I try the send a message via the contact form, I get the following error message:
SMTP Error: data not accepted.

I already checked the mail server credentials via a CLI tool, they are correct.

Have you tried to send to other recipients?

I just tried another recipient but i got the same error. I also tested without the auth settings. The result was no error on the formular but I do not reciev any mail.

And does the template exist?

There was a post some time ago which is about the security option: Kirby->Email / SMTP Error (Timeout?) - #10 by jango Seems like 'security' => true is not correct, but 'security' => 'ssl' or 'security' => 'tls'. Check also if you are using the correct port (which seems to be the case here).

Since 3.5.1, setting security => true should actually work by automatically picking the right protocol:

I tried both tls and ssl and also the tempaltes exists.

No idea what’s wrong in your case, but if you need more info from PHPMailer you can add

'beforeSend' => function ($mailer) {
  $mailer->SMTPDebug = 2;
  return $mailer;
}

to the β€˜email’ array in config, that will print a full report when trying to send the email.

Thank you, now I was able to get some more information.

First of all, the authentication works fine:
2021-04-27 12:46:39 SERVER β†’ CLIENT: 235 2.7.0 Authentication successful

But the error looks like this:
2021-04-27 12:46:39 SERVER β†’ CLIENT: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:3C040000, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:18230000, 1.36674:0E000000, 1.61250:00000000, 1.45378:1D230000, 1.44866:A8010000, 16.55847:6F110000, 17.43559:0000000024020000000000000000000000000000, 20.52176:140FE18F1B00F01F00000000, 20.50032:140FE18F8B17F01F0B004536, 0.35180:93050000, 255.23226:5
2021-04-27 12:46:39 SMTP ERROR: DATA END command failed: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 0.35250:3C040000, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:18230000, 1.36674:0E000000, 1.61250:00000000, 1.45378:1D230000, 1.44866:A8010000, 16.55847:6F110000, 17.43559:0000000024020000000000000000000000000000, 20.52176:140FE18F1B00F01F00000000, 20.50032:140FE18F8B17F01F0B004536, 0.35180:93050000, 255.23226:5
SMTP Error: data not accepted.
2021-04-27 12:46:39 CLIENT β†’ SERVER: QUIT

Okay I found now the problem. The from adress end with .com but acutally the TLD is .de
So I changed the from adress to .de and it worked fine :slight_smile: