E-Mail flag for users

From MoodleDocs

Changing the email flag of a user prevents/allows him from receiving emails from Moodle. Moodle contains a CLI script to change the email flag for one or many users at a time. Also, the current state whether the email flag is off or on can be displayed. A possible use case for this script is to automate process of scanning the log file of the mail transfer agent (e.g. postfix) and extract email addresses that are reported there. If an email is invalid/rejected for mail delivery, this address can be taken as an argument for the cli script to change the emailstop flag so that the user does not receive any further emails.

The CLI script emailstop.php is located in the admin/cli of the Moodle installation.

Accepted command line arguments are:

   -h, --help              Print out a help screen that mentions all possible agruments that can be set.
   -e, --email=email       Specify an user by email, separate many users by comma.
   -i, --id=id             Specify an user by the internal database id, separate many ids by comma.
   -q, --quiet             Do not print anything out to stdout. The success of the script can still be controlled by the exit code.
   -s, --stop=0|1|off|on   Set a new value for emailstop flag
   -u, --username=username Specify user by username, separate many users by comma.

To identify one or many users, only one of the options -e, -i, or -u can be used. For convenient reasons many users can be set at once, and must be separated by a comma e.g. php admin/cli/emailstop.php -u=student1,student2,student3.

The -q param prevents any output on stdout. Using -q qithout the -s argument doesn't make much sense then.

Sample calls:

   $ php admin/cli/emailstop.php --email=student1@example.org --stop=1 -q

Disable receiving email for the user with email student1@example.org. No output is generated.

   $ php admin/cli/emailstop.php --email=student1@example.org

Show the status of the email stop flag for the user with email student1@example.org.