Cron job attemtping to send email every 5 minutes

So received a phone call from my isp today asking questions about emails they received *some 6K emails over a short time :blush:
Looking in the logs I found repeated messages in my mail log pointing to successfully sent emails, but where the recipient is *just happened to be a valid email with my isp.
the www user seem to be tied to the cron job running as www scheduled every 15 minutes

crontab -u www -e
# minute (0-59),
# |     hour (0-23),
# |     |       day of the month (1-31),
# |     |       |       month of the year (1-12),
# |     |       |       |       day of the week (0-6 with 0=Sunday).
# |     |       |       |       |       commands
  */15      *       *       *       *       /usr/local/bin/php -f /usr/local/www/nextcloud/cron.php

The mail log show this…

Jul  2 17:50:00 nextcloud postfix/pickup[32599]: B35FC1CAD8: uid=80 from=<www>
Jul  2 17:50:00 nextcloud postfix/cleanup[33792]: B35FC1CAD8: message-id=<20200702095000.B35FC1CAD8@nextcloud.localdomain>
Jul  2 17:50:00 nextcloud postfix/qmgr[32600]: B35FC1CAD8: from=<>, size=748, nrcpt=1 (queue active)
Jul  2 17:50:01 nextcloud postfix/smtp[33794]: B35FC1CAD8: to=<>, orig_to=<www>,[]:587, delay=1, delays=0.66/0.01/0.18/0.19, dsn=2.0.0, status=sent (250 ok:  Message 304972311 accepted)
Jul  2 17:50:01 nextcloud postfix/qmgr[32600]: B35FC1CAD8: removed

As you see there;s an attempt to send a email out to that never reach me.
Dont understand why this is happening since the cron job simply is intended to refresh data - not actually send out an email.

postfix has been configured as this… *but still dont understand why an email is sent as part of the cron job ?

# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites.  If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#myorigin = $myhostname
#myorigin = $mydomain
myorigin =

Suspect that the owner *that should be www owner of the cron task ends up being the recipient when postfix builts its email and no idea how I can change this

Using FreeNAS 11.3-STABLE
nextcloud installed in its own jail.
Installed nextcloud: (php73 version)
Sorry to hear you’re facing problems :slightly_frowning_face: is for home/non-enterprise users. If you’re running a business, paid support can be accessed via where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:


Or for longer, use three backticks above and below the code snippet:


Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:


Nextcloud version (eg, 18.0.2):
Operating system and version (eg, Ubuntu 20.04):
Apache or nginx version (eg, Apache 2.4.25):
PHP version (eg, 7.1):

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N):

Steps to replicate it:

The output of your Nextcloud log in Admin > Logging:


The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):


The output of your Apache/nginx/system log in /var/log/____:


i’m afraid we would ne way more info to being able answering here.

Referring to the title of your posting it could be correct for cronjob to send emails… maybe something is wrong… we don’t know without any more infos

1 Like

Tell me what more info u need and I will provide it

The cron task simply points to /usr/local/www/nextcloud/cron.php

Why would this cron.php attempt to send an email? Nothing inside even suggesting it making an attempt?

 * @copyright Copyright (c) 2016, ownCloud, Inc.
 * @author Artem Sidorenko <>
 * @author Christopher Schäpers <>
 * @author Christoph Wurst <>
 * @author Damjan Georgievski <>
 * @author Daniel Kesselberg <>
 * @author Jakob Sack <>
 * @author Joas Schilling <>
 * @author Jörn Friedrich Dreyer <>
 * @author Ko- <>
 * @author Michael Kuhn <>
 * @author Morris Jobke <>
 * @author Oliver Kohl D.Sc. <>
 * @author Robin Appelman <>
 * @author Roeland Jago Douma <>
 * @author Steffen Lindner <>
 * @author Thomas Müller <>
 * @author Vincent Petry <>
 * @license AGPL-3.0
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program. If not, see <>

require_once __DIR__ . '/lib/versioncheck.php';

try {
	require_once __DIR__ . '/lib/base.php';

	if (\OCP\Util::needUpgrade()) {
		\OC::$server->getLogger()->debug('Update required, skipping cron', ['app' => 'cron']);
	if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) {
		\OC::$server->getLogger()->debug('We are in maintenance mode, skipping cron', ['app' => 'cron']);

	// load all apps to get all api routes properly setup


	// initialize a dummy memory session
	$session = new \OC\Session\Memory('');
	$cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
	$session = $cryptoWrapper->wrapSession($session);

	$logger = \OC::$server->getLogger();
	$config = \OC::$server->getConfig();

	// Don't do anything if Nextcloud has not been installed
	if (!$config->getSystemValue('installed', false)) {


	// Exit if background jobs are disabled!
	$appMode = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax');
	if ($appMode === 'none') {
		if (OC::$CLI) {
			echo 'Background Jobs are disabled!' . PHP_EOL;
		} else {
			OC_JSON::error(['data' => ['message' => 'Background jobs disabled!']]);

	if (OC::$CLI) {
		// set to run indefinitely if needed
		if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {

		// the cron job must be executed with the right user
		if (!function_exists('posix_getuid')) {
			echo "The posix extensions are required - see" . PHP_EOL;

		$user = posix_getpwuid(posix_getuid());
		$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
		if ($user['name'] !== $configUser['name']) {
			echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
			echo "Current user: " . $user['name'] . PHP_EOL;
			echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;

		// We call Nextcloud from the CLI (aka cron)
		if ($appMode !== 'cron') {
			$config->setAppValue('core', 'backgroundjobs_mode', 'cron');

		// Work
		$jobList = \OC::$server->getJobList();

		// We only ask for jobs for 14 minutes, because after 5 minutes the next
		// system cron task should spawn and we want to have at most three
		// cron jobs running in parallel.
		$endTime = time() + 14 * 60;

		$executedJobs = [];
		while ($job = $jobList->getNext()) {
			if (isset($executedJobs[$job->getId()])) {

			$job->execute($jobList, $logger);
			// clean up after unclean jobs

			$executedJobs[$job->getId()] = true;

			if (time() > $endTime) {
	} else {
		// We call cron.php from some website
		if ($appMode === 'cron') {
			// Cron is cron :-P
			OC_JSON::error(['data' => ['message' => 'Backgroundjobs are using system cron!']]);
		} else {
			// Work and success :-)
			$jobList = \OC::$server->getJobList();
			$job = $jobList->getNext();
			if ($job != null) {
				$job->execute($jobList, $logger);

	// Log the successful cron execution
	$config->setAppValue('core', 'lastcron', time());
} catch (Exception $ex) {
	\OC::$server->getLogger()->logException($ex, ['app' => 'cron']);
} catch (Error $ex) {
	\OC::$server->getLogger()->logException($ex, ['app' => 'cron']);

… and based on the frequency of the mail log, it seem to be tied to the cron task that runs every 15 minutes aimed at synchronizing nc data

crontab -u www -e
# minute (0-59),
# |     hour (0-23),
# |     |       day of the month (1-31),
# |     |       |       month of the year (1-12),
# |     |       |       |       day of the week (0-6 with 0=Sunday).
# |     |       |       |       |       commands
  */15      *       *       *       *       /usr/local/bin/php -f /usr/local/www/nextcloud/cron.php

so here’s an answer according to all the info you didn’t provide us so far.

Usually your instance shouldn’t do that.

So now it’s up to you to finally give out more info about your server, your setup, your server-environment, logs, etc.

ummm. The template you didn’t answer to in your first comment gives you all the hints you’d need, btw.

1 Like

Perhapy you can test ist manually:

sudo -u www /usr/local/bin/php -f /usr/local/www/nextcloud/cron.php
Post errors.

Why do you use php from /usr/local/bin ?

You also can deactivate cron.php and use e.g. AJAX. Only good for small installations.

No idea really, other than following the steps posted for FreeNAS going back a while

This chap posted something that actually managed me to get this up and running in its own jail - with a few security addons that I liked at the time - but this goes back several releases back

As for this problem, I have no idea how long its been going on

Reason I reverted to Ajax is because I made an attempt to prevent these mails being sent!

Normally I use cron


but even with opting for Ajax, this still shows up in the logs - just restarted the jail and voala…

Jul 2 21:31:01 nextcloud postfix/postfix-script[41565]: starting the Postfix mail system
Jul 2 21:31:01 nextcloud postfix/master[41567]: daemon started – version 3.5.3, configuration /usr/local/etc/postfix
Jul 2 21:35:01 nextcloud postfix/pickup[41568]: 520921D153: uid=80 from=
Jul 2 21:35:01 nextcloud postfix/cleanup[42154]: 520921D153: message-id= Jul 2 21:35:01 nextcloud postfix/qmgr[41569]: 520921D153: from=<>, size=748, nrcpt=1 (queue active) Jul 2 21:35:01 nextcloud postfix/smtp[42156]: 520921D153: to=<>, orig_to=,[]:587, delay=1.5, delays=1.3/0.03/0.11/0.05, dsn=2.0.0, status=sent (250 ok: Message 259894065 accepted) Jul 2 21:35:01 nextcloud postfix/qmgr[41569]: 520921D153: removed

For small installation AJAX works.
Also you can execute manually cron.php and look what happens.

You must deactivate your cron-job. Perhaps cron.php runs multiple times. Check it with “ps -aux” or other commands.

… and before you know it, it reverts back to cron - even due I opted for Ajax - so not sure whats going on with this - seem to sense that I still have a cron task scheduled somehow ???

I think with the setting to “Cron” nothing changes because you must define the cronjobs in crontab. There must be a cronjob in your linux system perhaps for another user (root) with “sudo -u www” (ugly implementation of cron). Check all cron entries and deactivate them.

You can execute cron.php in the shell for testing only once in an hour manually.

how do I deactivate the cron - simply deleting the schedule or…? Cron as a job runs by default - sure can shut it down, but can still see a cron service running

I have a cron task running as root within thin jail - Have setup Aide to check integrity - other than that nothing

Please search the file “cron.php” and only change the path to the right cron.php.
Where is your nextcloud installation (path)?

And please change also the port from 8080 to 443 and you a normal certificate (Lets Encrypt).

using ssl as w speak

nc installed in /usr/local/www/nextcloud

cron.php located in root of nc installation - and this is what the cron job is pointing to (attached)

(Attachment cron.php is missing)

using ssl as w speak

nc installed in /usr/local/www/nextcloud

cron.php located in root of nc installation - and this is what the cron job is pointing to (attached * attachment rejected so pasted inline)

<?php /** * @copyright Copyright (c) 2016, ownCloud, Inc.

In this cron file, you can define an email address:

     # use /bin/sh to run commands, overriding the default set by cron
     # mail any	output to `paul', no matter whose crontab this is
     # run five	minutes	after midnight,	every day
     5 0 * * *	     $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
     # run at 2:15pm on	the first of every month -- output mailed to paul
     15	14 1 * *     $HOME/bin/monthly
     # run at 10 pm on weekdays, annoy Joe
     0 22 * * 1-5    mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
     23	0-23/2 * * * echo "run 23 minutes after	midn, 2am, 4am ..., everyday"
     5 4 * * sun     echo "run at 5 after 4 every sunday"
     # run at 5	minutes	intervals, no matter how long it takes
     @300	     svnlite up	/usr/src


Don’t do that. This is probably not your domain (and never use someone else’s domain name here, no wonder they get angry!!!). Please only use your own domain. If you don’t want to run your own mailserver (and if you want, get to know the subject a bit better before by setting up a local mailserver in your local network only), use a mail-relay-server such as ssmtp instead.