Error when sending mail from command line as non-root user
I'm trying to send mail from the command line as a non-root user on CentOS. I'm using the following command but getting an error:
$ echo test | mail -s "test" [email protected] -c [email protected]
WARNING: RunAsUser for MSP ignored, check group ids (egid=102, want=51)
can not write to queue directory /var/spool/clientmqueue/ (RunAsGid=102, required=51): Permission denied
I've added the user to group 51 (smmtp) and I can both cd and write to that directory as the user.
Why am I getting the error?
Some relevant permissions:
# ls -la /var/spool/clientmqueue/
total 8
drwxrwx--- 2 smmsp smmsp 4096 Mar 8 14:25 .
drwxr-xr-x. 13 root root 4096 Oct 21 15:09 ..
# ls -la /usr/sbin/sendmail
lrwxrwxrwx 1 root root 21 Oct 21 15:09 /usr/sbin/sendmail -> /etc/alternatives/mta
# ls -la /etc/alternatives/mta
lrwxrwxrwx 1 root root 27 Oct 21 15:09 /etc/alternatives/mta -> /usr/sbin/sendmail.sendmail
# ls -la /usr/sbin/sendmail.sendmail
-rwxr-sr-x 1 root smmsp 833512 Nov 11 2010 /usr/sbin/sendmail.sendmail
Sendmail expects the email address to be the last thing in the command line. If you have any parameters after the email address, it will parse them as email addresses. In the example above, it's trying to parse "-c" as an email address and giving an unrelated error.
# BAD
$ echo test | mail [email protected] -s "test"
# BAD
$ echo test | mail [email protected] -c [email protected]
# GOOD
$ echo test | mail -s "test" -c [email protected] [email protected]
The TO email addresses have to follow the CC email addresses, the email subject, and any other parameters you need to pass to sendmail.
Even if binary has correct permissions, programs in /usr/sbin
are not runnable directly (not seen in path) to a normal user, write the whole path.
Use like so:
echo "Subject: sendmail test" | /usr/sbin/sendmail -v [email protected]