Operating System - Linux
1835259 Members
2421 Online
110078 Solutions
New Discussion

Re: Changing the from line in sendmail.

 
SOLVED
Go to solution
Don Mallory
Trusted Contributor

Changing the from line in sendmail.

Hi everyone,

Here's the challenge, I want my email notifications from my Red Hat Enterprise Linux 4ES nodes to look just like my HP-UX nodes.

By default, the HP-UX nodes have a from both displayed and the actual address of:

username@hostname.domain.com

Such as root@banana.hp.com

When I receive a message from a Linux node, it shows a displayed name as the username and the email address as the full address.

So, in your email you see a message from:

root

Who has an address of:

root@linuxnode.domain.com

I'd like it to look just like HP-UX.

Does anyone have any ideas where I should start? I've tried comparing the sendmail.cf files, but, well, they're brutal.

Another quick one. Why is it that some documentation says you should make changes to the sendmail.mc file and run m4 to generate the sendmail.cf file, and others say just to edit the sendmail.cf.

From what I've seen, both files are awful to work with, so I don't see any benefit in workin with the .mc then having to deal with a script tool as well. Am I wrong here?

Thanks,
Don
11 REPLIES 11
Steven E. Protter
Exalted Contributor

Re: Changing the from line in sendmail.

An entry in /etc/mail/virtusertable and possibly /etc/mail/genericstable will do it.

You'll need to do this on each machine.

Don't have to touch sendmail.cf sendmail.mc or even restart the sendmail daemon.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ivan Ferreira
Honored Contributor

Re: Changing the from line in sendmail.

I did not understood your question. From the linux, do you receive root@hostname.domain or just root@domain?

The sendmail.mc is a macro file that allows you to generate a sendmail.cf file. It's popular because it's really easy configure sendmail with that, but also, you can edit directly the sendmail.cf file.

The good thing of sendmail.mc is that, when you upgrade the version of sendmail, you can quickly generate a new .cf file.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ivan Ferreira
Honored Contributor

Re: Changing the from line in sendmail.

Forgot to add, you can control the domain part using the MASQUERADE_AS option in the sendmail.mc file, or configure the Dj (j is the host name) and DM (M is the masquerade as) in the sendmail.cf file
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Don Mallory
Trusted Contributor

Re: Changing the from line in sendmail.

Hmm.. perhaps I should give specific examples instead. It would probably help with me not being quite so obtuse.

If I log into an HP-UX 11.11 box and enter the following:

echo done | mailx -s "testing" username@domain.ca

I get the following message header in my email:

Received: from hpux.domain.ca ([192.168.1.32]) by smtphost.domain.ca with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
id 4KNAG76Z; Thu, 13 Oct 2005 20:15:04 -0400
Received: (from root@localhost)
by hpux.domain.ca (8.9.3 (PHNE_29774)/8.9.3) id UAA17263
for username@domain.ca; Thu, 13 Oct 2005 20:15:17 -0400 (EDT)
Date: Thu, 13 Oct 2005 20:15:17 -0400 (EDT)
From: root@hpux.domain.ca
Message-Id: <200510140015.UAA17263@hpux.domain.ca>
To: username@domain.ca
Subject: testing
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


If I log into a Red Hat Enterprise Linux 4ES box and enter:

echo testing | mail -s "testing" username@domain.ca

I get this header:

Received: from linux.domain.ca ([192.168.1.34]) by smtphost.domain.ca with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
id 4KNAG76R; Thu, 13 Oct 2005 20:14:28 -0400
Received: (from root@localhost)
by linux.domain.ca (8.13.1/8.13.1/Submit) id j9E0ER80003318
for username@domain.ca; Thu, 13 Oct 2005 20:14:27 -0400
Date: Thu, 13 Oct 2005 20:14:27 -0400
From: root
Message-Id: <200510140014.j9E0ER80003318@linux.domain.ca>
To: username@domain.ca
Subject: testing



How do I make the Linux one be just like the HP-UX one?


SEP: Since I've read many sendmail responses from you, I don't doubt that what you are suggesting will solve the problem.. (what can I say, you seem to be a sendmail god.. ;-) The thing is, my HP-UX boxes don't have either of those files, and they work just fine...

I'm going to attach the sendmail.cf from one of each of my linux and hpux nodes so you can see what I see...


Don Mallory
Trusted Contributor

Re: Changing the from line in sendmail.

And the linux sendmail.cf file.
Arunvijai_4
Honored Contributor

Re: Changing the from line in sendmail.

You can use DM macro,
# Masquerade as (DM): #
# #
# If you wish to have mail appear to be from some host or location #
# other than the local host, set macro M to the name you wish to #
# masquerade as. This is also know as site hiding and was set using #
# the DY macro in previous releases of hp-ux.
"A ship in the harbor is safe, but that is not what ships are built for"
Muthukumar_5
Honored Contributor

Re: Changing the from line in sendmail.

I found only one difference between hpux sendmail.cf and linux as,

O MaxHeadersLength=32768

Enable this in linux and restart sendmail.

Try it and post results.

hth.
Easy to suggest when don't know about the problem!
Tom Callahan_1
Advisor

Re: Changing the from line in sendmail.

use `sendmail -fuser@host.com toaddr@host.com`

The -f specifies the from address to be user@host.com

Thanks,
Tom Callahan
Don Mallory
Trusted Contributor

Re: Changing the from line in sendmail.

I recognise that your suggestion will work (and it does) the thing is, I don't have to do that on the HP-UX boxes, and what you are suggesting will require re-writing a large number of scripts, when I can just fix the configuration of sendmail instead...
Ermin Borovac
Honored Contributor
Solution

Re: Changing the from line in sendmail.

File that's used for outgoing email on RHEL is /etc/mail/submit.cf.

In this file you will find the following line (in the "Format of headers" section)

H?F?From: $?x$x <$g>$|$g$.

This is where your From header is set and it is sendmail's equivalent of if statement.

if ($x is set)
then
set From: to $x <$g>
else
set From: to $g

$x is full name of the sender (gecos field from the /etc/passwd).
$g is sender's address

SO one way to transform "root " to just "root@..." in "From:" field is to simply leave gecos field for root account in /etc/passwd empty.

i.e.

change

root:x:0:0:root:/root:/bin/bash

to

root:x:0:0::/root:/bin/bash

Hope that makes sense.
Don Mallory
Trusted Contributor

Re: Changing the from line in sendmail.

That's awesome! I completely forgot about the submit.cf!

I changed:

#H?F?From: $?x$x <$g>$|$g$.

To:

H?F?From: $g$

And it does exactly what I'm looking for.

Thanks a lot!
Don