Sending Emails as a non root user using mailx command in Linux failed.

While sending Emails using mailx with a  non root user below error occurred. Default MTA used is ssmtp

[test@myhost ~]$ echo "something" | mailx -s "subject" gulfit@gulffinance.com
temporary mail file: Permission denied

But from root I was able to send a test mail. Please help
GulfITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
Your issue is a permission/configuration issue dealing with the editor VISUAL/EDITOR and the location where it tries to store the messages prior to transmission /tmp /var/tmp

If this is to be used in a script, creating the message and sending it through the commonly available /usr/sbin/sendmail
GulfITAuthor Commented:
Thanks Arnold, I am just trying to send mails from a non root user, need to know the path of the temporary  email file so that I can give permission for non root users as well. Please advise .
arnoldCommented:
Try using mail instead of mailx. Mailx is a graphical versus mail which is not.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

GulfITAuthor Commented:
Thanks .same error

[user@gfcsrv ~]$  mail -s "subject" admin@gulfinance.com
temporary mail file: Permission denied

Regards.
Zephyr ICTCloud ArchitectCommented:
Do you have a mail group? Maybe the user isn't in the mail group?
arnoldCommented:
echo $EDITOR
echo $VISUAL

Can a regular user write into /tmo  or /var/tmp?

A user must not be added to the mail group as it is unnecessary and .........
GulfITAuthor Commented:
This user is a part of default mail group .
arnoldCommented:
There is absolutely no reason a user needs to be a member of a mail group.
id user
To see to which groups it belongs, remove the mail group, and see if the issue is resolved.
GulfITAuthor Commented:
Removed from mail group and tried , still same permission issue.Is mailx works with a non root user ?
arnoldCommented:
What are the output from the variables?
Can you create a file as the non root user in /tmp?
Try the following as non root

echo "To: recipient
From: sender
Subject: test

Message
" | /usr/sbin/sendmail -oi -t

Does this work?
GulfITAuthor Commented:
I can write into /tmp folder as a non root user. output from the variable is copied. not showing any thing.

[user@gfcfcdb1 ~]$ echo $EDITOR

[user@gfcfcdb1 ~]$ echo $VARIABLE

[user@gfcfcdb1 ~]$

##########################################################################

user@gfcfcdb1 ~]$ echo "To: sreejith@gulfinance.com From:gfcfcdb@gulfinance.com Subject: test Message " | /usr/sbin/sendmail -oi -t
sendmail: RCPT TO:<sreejith@gulfinance.com From:gfcfcdb@gulfinance.com Subject: test Message> (501 5.1.3 Invalid address)
arnoldCommented:
The entries have to be on individual lines as displayed in the post.
export EDITOR=/bin/vi
And try again.
GulfITAuthor Commented:
Yes , that is working as a non root user. but mailx doesn't.
Zephyr ICTCloud ArchitectCommented:
What distro are you using? Ubuntu/Debian/Redhat/Centos ?
arnoldCommented:
Are you able to create a file with a non-root user in /tmp
ls -l / | grep -i tmp
getfacl /tmp

It looks as though you have the wrong permissions on  /tmp
I.e. it is not group/world readable/writeable.
GulfITAuthor Commented:
Hi Arnold,
  I am able to create files in tmp as a non root user.

Copied the out put of below commands.

[user@gfcfcdb1 ~]$ ls -l / | grep -i tmp
drwxrwxrwx.  27 root root  4096 Jun 24 09:49 tmp
[user@gfcfcdb1 ~]$ getfacl /tmp
getfacl: Removing leading '/' from absolute path names
# file: tmp
# owner: root
# group: root
user::rwx
group::rwx
other::rwx
arnoldCommented:
Look at /etc/mail.rc
It is a peculiar situation,  not sure where the issue begins.

One option is to try the following
Create a message file single line hey is fine. Message.file
strace mailx -s "subject" admin@yourdomain.com < Message.file

Look at the output to see where the error occurs meaning what and when it tries to access.

When you run mail as a non root user, what options do you get or does it error out as well?
Zephyr ICTCloud ArchitectCommented:
If it's Redhat or one of its derivatives you could also check this KB

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GulfITAuthor Commented:
Done
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.