Error 503 on resending welcome email by occ command and curl in 29.0.5

Nextcloud version: 29.0.5
Operating system: Shared host Linux
Apache version: 2.4
PHP version: 8.2

The issue you are facing:

After updating Nextcloud from version 28 to 29, I am facing with the error 503 when using url ocs/v1.php/cloud/users/{userid}/welcome with curl command from a SSH terminal and php-cli 8.2.

On the other hand, the email is correctly sent if I use the option ‘send welcome mail’ from the web interface using the same user (administrator).

This has been working fine until NC 28.

Steps to replicate it:

  1. Create a PHP script (let’s call it ‘mailsender.php’) similar to:
<?php
$username = 'michael';
$options[CURLOPT_URL] = 'https://mydomain/nextcloud/ocs/v1.php/cloud/users/' . urlencode($username) . '/welcome';
$options[CURLOPT_PORT] = 443;
$options[CURLOPT_USERPWD] = $oc_user . ':' . $oc_pass;
$options[CURLOPT_FRESH_CONNECT] = true;
$options[CURLOPT_FOLLOWLOCATION] = true;
$options[CURLOPT_FAILONERROR] = true;
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_TIMEOUT] = 15;
$options[CURLOPT_POST] = true;
$options[CURLOPT_HEADER] = true;
$options[CURLOPT_HTTPHEADER] = array("OCS-APIRequest: true");
$curl = curl_init();
curl_setopt_array($curl, $options);
if (curl_exec($curl) === false) {
	echo "[Request ERROR] Welcome email sent to " . $username . " failed!: " . curl_error($curl) . PHP_EOL;
}
else {
	echo "[Request OK] Sent welcome email to " . $username . PHP_EOL;
}
curl_close($curl);
?>

, where $oc_user and $oc_pass are the credentials for an admin user.

  1. Upload the script to a folder in the same host of the NC installation.

  2. Open a SSH shell and type:

/usr/bin/php8.2-cli /path_to_my_server/htdocs/mailsender.php

  1. Result:
    [Request ERROR] Welcome email sent to michael failed!: The requested URL returned error: 503

Please, anyone can help?

Thanks in advance.

Well, it seems that there was a problem with IONOS servers. Now the PHP script works again.

However, if somebody wants/needs another way of doing the same, you can change the script like this:

<?php
 $command = 'curl -X POST https://mydomain/nextcloud/ocs/v1.php/cloud/users/' . $username . '/welcome -u ' . $oc_user . ':' . $oc_pass . ' -H "OCS-APIRequest: true"';
exec($command, $output, $status);
$output = implode(' ', $output);
if ($status !== 0)
	echo "[Request ERROR] Welcome email sent to " . $username . " failed!: " . $status . " - " . $output . PHP_EOL;
else {
	if (str_contains($output, '<statuscode>100</statuscode>'))
		echo "[Request OK] Welcome email sent successfully!" . PHP_EOL;
	else if (str_contains($output, '<statuscode>101</statuscode>'))
		echo "[Request ERROR] Email address not available for user '" . $username . "'" . PHP_EOL;
	else if (str_contains($output, '<statuscode>102</statuscode>'))
		echo "[Request ERROR] Sending email failed for user '" . $username . "'" . PHP_EOL;
}
?>

Regards!

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.