sendmail - changing root in the from address

Latest response

Trying to change the from address from root@localhost.localdomain to user@mydomain.com
Using MASQUERADE options in sendmail.mc I was able to change the domain so now my emails are coming from root@mydomain.com
I am not able to find out how to change the to

I did some searches here and on the net but couldn't find a solution for RHEL

Any help/suggestion greatly appreciated

Thanks,

Responses

Since you have root, perhaps you could create an user account and use that for sending your email, perhaps? Don't use the root account for regular user tasks - if you find that you do something that often requires root access, perhaps learn how to give your regular user account the necessary permissions, or some other easy way to accomplish the things you need most often.

If you're implementing something that needs to send email using the "sendmail" command and must present a specific sender address, see sendmail command line options -F and -f.

Remember that if you send an email with user@mydomain.com as the From address, any replies to it will come back to that address by default - including any mail delivery error messages, which might be helpful in detecting and solving a mail configuration problem. If you cannot actually receive email as user@mydomain.com, those replies will be lost to you.

Thanks Matti.

root was an example. Maybe I should say replace Linux user ID@localhost.localdomain with generic name@my domain

We have apps/Oracle DBs that rely on sendmail to send emails and they are not easy configurable to manually add the "From" address (or at least the DBAs are not very cooperative :-) ).

We don't care about replies we don't use that part.

I know it can be done by playing with sendmail.cf or something around that but couldn't find any reference on how to do it.

Matti, replacing root@localsystem.domain.tld with a distribution group of administrators is good for catching crontab emails. Similarly, replacing uname@localsystem.domain.tld with User.Name@domain.tld is useful for systems other than the main mail server for the organization. I tried to do this back in RHEL 5, integrating LDAP (automatically pull email address associated with account and replace account@hostname with LDAP email address). Unfortunately I could never get it to work with Sendmail. (Part of the problem is that the sendmail.mc in the rpm did not generate the sendmail.cf in the rpm as of RHEL 5, so trying to add things caused other configuration changes at the same time.)

Ah, now I see what you're after.

You'll need to enable the "genericstable" feature of Sendmail. To do that, you'll need to replace the standard sendmail.cf with a customized one - and the best way to create a customized sendmail.cf is to use the sendmail.mc file.

The following procedure should apply exactly for RHEL 6.x. Older or newer major versions may have some minor differences.

First, ensure that the "sendmail-cf" RPM is installed. This brings with it the necessary macro files for regenerating the Sendmail configuration file. Then, if you have made any changes to the current sendmail.cf directly, make the matching changes to /etc/mail/sendmail.mc file too. For example, if you have edited the DS line in sendmail.cf to specify your central mail server, you should find this line in sendmail.mc:

dnl define(`SMART_HOST', `smtp.your.provider')dnl

and change it to:

define(`SMART_HOST', `smtp.your.provider')dnl

(replacing the "smtp.your.provider" with the fully-qualified DNS name of your mail server, of course).

Note that the language used in sendmail.mc is different and more verbose, and the m4 macro processor that is used to generate the sendmail.cf file is very sensitive to extra characters at the ends of lines. ("dnl" in sendmail.mc actually means "anything on this line after this is a comment")

After the "FEATURE(` virtusertable', ..." line, add a new line:

FEATURE(`genericstable', `hash -o /etc/mail/genericstable.db')dnl

Note the special way of using the quote characters: they must be specified exactly the same way as on the previous virtusertable FEATURE line.

After adding this line to /etc/mail/sendmail.mc, run the following commands:

# cd /etc/mail
# touch genericstable
# ./make

This command will save your existing sendmail.cf as sendmail.cf.bak create a new one based on sendmail.mc, and also generate a genericstable.db file for you. Now you can specify username mappings for the From addresses in /etc/mail/genericstable like this:

user_ID                                   generic.name@my.domain
user_ID@localhost.localdomain     generic.name@my.domain

After each time you edit the /etc/mail/genericstable file, you should regenerate the corresponding genericstable.db file by running:

# cd /etc/mail
# ./make

When the sendmail-cf RPM is installed, the sendmail RPM will automatically use the settings in /etc/mail/sendmail.mc to regenerate the sendmail.cf file each time Sendmail is updated.

Once you know about the RedHat-specific sendmail-cf RPM and the /etc/mail/make script, you can apply all the generic Sendmail tricks that can be expressed in the sendmail.mc file. Anything that depends on editing the sendmail.cf directly should be considered as highly Sendmail-version-dependent deep magic: such solutions are brittle and can become unusable as Sendmail is updated.

The standard reference for Sendmail is the book "Sendmail" by O'Reilly. It's a big and intimidating book, but most of it is occupied by a dictionary of all the configuration keywords and options. To effectively become a Sendmail wizard, you'll only need to read and understand the first 10 or so chapters, and then use the rest as a reference and look up only the things you actually need. Trying to actually read the book from cover to cover is only slightly more interesting than reading the phone book.

I have followed the same process, but it didn't work. Am I missing anything? I am using CentOS Linux release 7.5.1804 and sendmail-cf-8.14.7-5.el7 version.

Update - I have added the below line in sendmail.mc file and updated /etc/mail/generics-domains with the fqdn of my server. It solved the issue.

GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl

I have followed the steps documented here but still not working. I am using RedHat 6.6.