Cron to send email as another user

peterr

Well-Known Member
Sep 24, 2003
85
0
156
Whether it be PHP, Perl or other scripts, when one sends an email the "username" is contained within the email headers. So, this is a concern to me, as emails go through many gateways as plain text, and that username is the Cpanel/website root username. The objective is to keep the username private.

There are, seemingly, methods to change email headers, however I don't want to go down that path (again), ..time wasting, it doesn't replace the username.

So, now the question. If I create a new user from CPanel, then have a cron job for the new user to do system checks, etc, and then conditionally send an email, will the email headers from the cron job contain the new user ?? Sounds feasible.

Of course that new user will need to have privileges to search for files, sometimes move files, delete files and send emails, etc
 

peterr

Well-Known Member
Sep 24, 2003
85
0
156
Hey there! I'm not sure what the "new user" you're referring to would be. Can you get me more details on that? I'm not very clear on where that new user is coming from.
CPanel | Preferences | User Manager

This interface allows you to manage subaccounts. Subaccounts use the same login and password information for email, FTP, and Web Disk services. The system synchronizes the password of each of the subaccount’s allowed services. Want to learn more? Read our documentation. - User Manager | cPanel & WHM Documentation
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
7,442
1,004
313
cPanel Access Level
Root Administrator
Thanks for the details - I was assuming that was it, but just wanted to be sure.

This user wouldn't have the ability to make cron jobs as that would still be up to the main cPanel user, so that wouldn't change the behavior you're experiencing.

For the user's cron you can set the mail with the following:

Code:
* * * * * job_command 2>&1 | mail -s "message subject here" -S [email protected] [email protected]
Could you try that to see if you get better results?
 
  • Like
Reactions: peterr

peterr

Well-Known Member
Sep 24, 2003
85
0
156
This user wouldn't have the ability to make cron jobs as that would still be up to the main cPanel user, so that wouldn't change the behavior you're experiencing.
I run a *nix box here, and if I add a user, I can then grant access to various function via privileges. I assumed that is what a 'user' is on CPanel, but maybe not.

For the user's cron you can set the mail with the following:

Code:
* * * * * job_command 2>&1 | mail -s "message subject here" -S [email protected] [email protected]
Could you try that to see if you get better results?
I have assumed you inferred the main/current "user" , therefore didn't add a new user. Then tried the cron, of course the sender and recipient can be modified, but the "user" is still in the email headers, which is exactly what I have experienced in the past. Checking threads at Change the sender name php mail instead of [email protected] and How to change the "from" header while sending an email from cpanel? , that is what I have tried in the past. All those mods do is change email addresses, and I even made mods to php.ini in the past, all to no avail, ..lol

Because the (Cpanel) user is the source of the cron job, Exim and other MTA's will always insert that username into the email headers.

I may add a new user via CPanel and do some testing. Thanks for your help. :)
 

peterr

Well-Known Member
Sep 24, 2003
85
0
156
Possibly there are limitations within CPanel, with my usage I mean, as I'm only one user on a shared server. Maybe user is the wrong approach ? It does seem that the MTA level decides what it will use by hostname, came across
Sendmail gets its own hostname from the first host found for itself in /etc/hosts.
So, just saying that I don't think I can override the hostname, in my situation, using CPanel on a shared server.