Sendmail on Plesk – user is not allowed to send mail
I recently ran into a strange problem on a Plesk server where one subscription was inexplicably unable to send email using sendmail (which is what the PHP mail() function uses).
The following was being logged in /var/logs/maillog for each attempt:
plesk sendmail: handlers_stderr: ERROR:__main__:Rejecting message: system user uid='<user ID>’ is not allowed to send mail
plesk sendmail: handlers_stderr: DATA REPLY:554:5.7.0 Your message could not be sent. The user <user name> is not allowed to send email.
plesk sendmail: handlers_stderr: REJECT
plesk sendmail: REJECT during call ‘limit-out’ handler
When calling sendmail from the command line, logged in as the user in question, I got:
Mail handler ‘limit-out’ said: REPLY:554:5.7.0 Your message could not be sent. The user logbookloans247 is not allowed to send email.
Plesk have a particularly useless knowledge base article which says that this is due to the mail service being disabled for the domain; https://support.plesk.com/hc/en-us/articles/360002410214-Unable-to-send-an-email-via-Wordpress-Rejecting-message-system-user-uid-xx-is-not-allowed-to-send-mail
This is nonsense – disabling the mail service is routine when email for a domain is hosted externally and so the server shouldn’t act as the final destination for email to this domain so as not to cause problems for any locally generated email destined for that domain.
Just to double check, I enabled the mail service on the domain, but unsurprisingly the problem persisted.
I checked several other Plesk servers and there were no other occurrences of this message in the mail logs, so this appeared to be an account specific problem.
I therefore tried fiddling with the outbound mail limits for the domain and the subscription, but no luck.
Eventually I stumbled on some users on the Plesk forums having a similar but unrelated problem, however this led me to the /usr/local/psa/admin/sbin/mailmng-outgoing command and through a bit of experimentation I found that the system user seemed to be missing, which I was able to add with the following command:
/usr/local/psa/admin/sbin/mailmng-outgoing --add-sysuser --main-domain-name=<domain name> --sysuser=<system user>
After doing this, sendmail and thus mail() worked as normal.