Link to home
Start Free TrialLog in
Avatar of damieneowen
damieneowen

asked on

Configure MTA on CentOS (RHEL)

I have a CentOS 4 linux machine on my local network at work. Just incase you didn't know CentOS is a free version of RedHat Enterprise Linux (I'm sure you alerady knew that though).

I want to be able to send mails from within a shell script using 'mail', 'sendmail', 'mailx' or whatever. The box is not configured to send mail nothing happends when I use:
 echo "blah blah" | mail -stest mail@address.com

I'm not sure where to start to configure a mail transport agent, or which one will be easiest to use. I'm not even sure if there is an MTA installed. I was hopping I could just point the box at our ISPs smtp server and that would be it. Something tells me it wont be that easy though.

I need to know:
 - The easiest way to check which (if any) MTA is installed.
 - Which one to use and how to install it (I'm guessing yum is the way forward).
 - What config settings I need to change for me to be able to send mails.

Thanks guys
Avatar of Kerem ERSOY
Kerem ERSOY

Hi,

thanks for the quick info about CentOS :)

The best way to understand is to know if you've tweaked the settings. In fact if you've  installed the default configuratiıon the RedHAT (you know CentOS is a free RedHAT clone built from SRPMS that is publicly available in RedHAT site.)

It is easy to understand though. just issue:
lsof -i :smtp

it will give you either something like this:
# lsof -i :smtp
COMMAND   PID USER   FD   TYPE DEVICE SIZE NODE NAME
sendmail 3202 root    4u  IPv4   7100       TCP aaa.xx.com:smtp (LISTEN)

(you're running sendmail)

Or it will output something like this:
# lsof -i :smtp
COMMAND   PID    USER   FD   TYPE DEVICE SIZE NODE NAME
smtpd   15511 postfix    6u  IPv4 156401       TCP *:smtp (LISTEN)
master  28037    root   11u  IPv4 156401       TCP *:smtp (LISTEN)

(you are using postfix)



SOLUTION
Avatar of ygoutham
ygoutham
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
after editing the sendmail.mc, then you probably need to use the following

m4 sendmail.mc > sendmail.cf
make
service sendmail restart

sendmail is a default option installed as a system file even if the base module is selected.

check to see if there is a sendmail executable file in /bin, /sbin or try /usr/local/bin, /usr/local/sbin

g
Avatar of damieneowen

ASKER

OK, so sendmail is installed.

I attempted to send a mail using the following but nothing happened.
      sendmail -i user@host.com < /some/text/file.txt

So I checked the sendmail.cf and made the following change to point to my ISPs smtp server:

ORIGINAL

dnl # Uncomment and edit the following line if your outgoing mail needs to
dnl # be sent out through an external mail server:
dnl #
dnl define(`SMART_HOST',`smtp.your.provider')

UPDATED

dnl # Uncomment and edit the following line if your outgoing mail needs to
dnl # be sent out through an external mail server:
dnl #
dnl define(`SMART_HOST',`relay.plus.net')

Then installed
  sendmail.cf
Then ran
  m4 sendmail.mc > sendmail.cf
  make
  service sendmail restart

Still no email received. Noticed the following in /var/log/maillog:
Oct 30 12:14:31 ceasar sendmail[5086]: k9UCEU16005084: k9UCEV16005086: DSN: User unknown
Oct 30 12:14:31 ceasar sendmail[5086]: k9UCEV16005086: to=<root@ceasar.localdomain>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31583, dsn=2.0.0, stat=Sent
                       
Also got the following mail in the root inbox:

   ----- The following addresses had permanent fatal errors -----
<damieno@sandyxsystems.co.uk>
    (reason: 550 <root@ceasar.localdomain>: Sender address rejected: Domain not found)

   ----- Transcript of session follows -----
... while talking to mailserver.sandyxsystems.co.uk.:
>>> DATA
<<< 550 <root@ceasar.localdomain>: Sender address rejected: Domain not found
550 5.1.1 <damieno@sandyxsystems.co.uk>... User unknown
<<< 554 Error: no valid recipients

--k9UAlOMj004602.1162205244/ceasar.localdomain
Content-Type: message/delivery-status

Reporting-MTA: dns; ceasar.localdomain
Received-From-MTA: DNS; ceasar.localdomain
Arrival-Date: Mon, 30 Oct 2006 10:46:56 GMT

Final-Recipient: RFC822; damieno@sandyxsystems.co.uk
Action: failed
Status: 5.1.1
Remote-MTA: DNS; mailserver.sandyxsystems.co.uk
Diagnostic-Code: SMTP; 550 <root@ceasar.localdomain>: Sender address rejected: Domain not found
Last-Attempt-Date: Mon, 30 Oct 2006 10:47:23 GMT

--k9UAlOMj004602.1162205244/ceasar.localdomain
Content-Type: message/rfc822

Return-Path: <root@ceasar.localdomain>
Received: from ceasar.localdomain (ceasar.localdomain [127.0.0.1])
        by ceasar.localdomain (8.13.1/8.13.1) with ESMTP id k9UAkuMj004600
        for <damieno@sandyxsystems.co.uk>; Mon, 30 Oct 2006 10:46:56 GMT
Received: (from root@localhost)
        by ceasar.localdomain (8.13.1/8.13.1/Submit) id k9UAK7cj004447
        for damieno@sandyxsystems.co.uk; Mon, 30 Oct 2006 10:20:07 GMT
Date: Mon, 30 Oct 2006 10:20:07 GMT
From: root <root@ceasar.localdomain>
Message-Id: <200610301020.k9UAK7cj004447@ceasar.localdomain>

create table tab1(
col1 integer
);
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
KeremE -

>Yo comment out this from the m4 file:

>dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

In my sendmail.cf the above line does exist but there is no 'dnl' on the front. What do I need to do comment this line out? Do I just stick a '#' on the front?

Also what does 'dnl' mean, what significance does it have in the .cf file?

The section for domain masquerading you mention is already in my .cf file, exactly as you have listed it. What do I need to do make this section work? Which lines to I need to un-comment/modify.

Thanks
in sendmail config file there is no option for #

you need to use dnl to comment out any unwanted lines. and remove dnl to uncomment.  the # is put there only to make the end user to understand that it is a comment and any uncommented line is void of "dnl #".  remove the loopback restriction (kereme's post above) and then it should be working fine.

goutham
after making the changes do I need to take any steps to apply the changes? i.e. m4..... and make. I tried these but make reported "nothing to be done for 'all'".

thanks
just do a "service sendmail restart"

run a "netstat -tap" to see if the port 25 is open for "0.0.0.0:25   LISTENING" which would indicate that the mails can be transported back and forth from the internet.

goutham
Hi,
I mean the .mc file.

when I say comment this line it is enough to add a # after dnl then the  line is ignored.

This is for the .mc file not the .cf. After you got the .ffile copy it over to your /etc/mail folder.

to restart sendmail you can do as ygoutham indicated. "service sendmail restart"

Wtch you logs for any problems taht sendmail could complain. You can use

lsof -i :smtp

to see if your daemon is listening to port 25

Cheers,
k.
still not working

Below is what gets posted in /var/log/maillog

Oct 31 12:57:33 ceasar sendmail[6493]: k9VCvX0Q006493: from=<root@ceasar.localdomain>, size=330, class=0, nrcpts=1, msgid=<200610311257.k9VCvX4P006492@ceasar.localdomain>, proto=ESMTP, daemon=MTA, relay=ceasar.localdomain [127.0.0.1]
Oct 31 12:57:33 ceasar sendmail[6492]: k9VCvX4P006492: to=damieno@sandyxsystems.co.uk, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30035, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (k9VCvX0Q006493 Message accepted for delivery)
Oct 31 12:57:33 ceasar sendmail[6495]: k9VCvX0Q006493: to=<damieno@sandyxsystems.co.uk>, ctladdr=<root@ceasar.localdomain> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=120330, relay=relay.plus.net. [212.159.11.46], dsn=5.1.1, stat=User unknown
Oct 31 12:57:33 ceasar sendmail[6495]: k9VCvX0Q006493: k9VCvX0Q006495: DSN: User unknown
Oct 31 12:57:33 ceasar sendmail[6495]: k9VCvX0Q006495: to=<root@ceasar.localdomain>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31583, dsn=2.0.0, stat=Sent

Below is the part of the sendmail.mc I've edited for the domain masquerading:

LOCAL_DOMAIN(`host.sandyxsystems.co.uk')dnl
dnl #
dnl # The following example makes mail from this host and any additional
dnl # specified domains appear to be sent from mydomain.com
dnl #
MASQUERADE_AS(`sandyxsystems.co.uk')dnl
dnl #
dnl # masquerade not just the headers, but the envelope as well
dnl #
FEATURE(masquerade_envelope)dnl
dnl #
dnl # masquerade not just @mydomainalias.com, but @*.mydomainalias.com as well
dnl #
FEATURE(masquerade_entire_domain)dnl
dnl #
dnl MASQUERADE_DOMAIN(localhost)dnl
MASQUERADE_DOMAIN(host.sandyxsystems.co.uk)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
MAILER(smtp)dnl

I've rerun make and restarted the sendmail service.

From what I can make out the domain masquerading isn't working because the log file shows the mail as coming from root@ceasar.localdomain.
lsof -i :smtp
COMMAND   PID USER   FD   TYPE DEVICE SIZE NODE NAME
sendmail 6480 root    4u  IPv4 183969       TCP *:smtp (LISTEN)

netstat -tap
tcp        0      0 *:smtp                      *:*                         LISTEN      6480/sendmail: acce
Hi,

Masquarading does not work for some users like root.
change the LOCAL_DOMAIN part to

LOCAL_DOMAIN(`localhost.localdomain')dnl

please note the tilted quote and a reqular single quote.  that is to indicate to the system that ceaser@localhost is also a valid user as well as ceaser@sandyxsystems.co.uk being the same user.  probably that might help.

i have a similar setup and it works fine but for the above line.

once all this is done do a "make", "m4 ....", "service sendmail restart"

then try out

telnet localhost 25
MAIL FROM: <sandy@sandyxsystems.co.uk>
RCPT TO: <damieno@sandyxsystems.co.uk>
DATA
Subject: Testing sending capabilities...

test 123

.

you should get a 250 message accepted for delivery message if everything goes well.

g
read last post like

once all this is done do a "m4 ...", "make", "service..."
remove

EXPOSED_USER(`root')


from your .m4 filr this will inhibit root not translated..
Good work, I the mail was sent successfully when I was logged in as a normal user.

Is there any way to enable root to send mails this way?

Also when I recieved the mail it was addressed to "undisclosed-recipients: ;" as though I had used the BCC field. Any way I can avoid this behaviour and just have the recipients address shown?
congrats!!!!
Hi,

If you remove the EXPOSED_USER from your .mc as per my previous posting you'll be able to masquarade root too.

undisclosed recipients mean hat your envelope does not include any recipient = you are using BCC. This is added automatically by receiving MTA.
 To avoid this just try to include some recipints in To: and/or Cc: field.


Cheers,
K.
Can send mails as root now so that's fine.

>To avoid this just try to include some recipints in To: and/or Cc: field.

After looking at man page for sendmail I can't see a way to add "To" or "cc" recipients when using sendmail. I can solve this using mail or mailx but they don't have a "-f" option to set the name of the sender. Any suggestions?
You can't do it with sendmail from the command line you can only do that in the envelope.

for moe information just look at here:

https://www.experts-exchange.com/questions/20852113/mail-and-sendmail-command-line-options.html

Another option is to add:

EXPOSED_USER('roottoor')    <--- esposed user will not be root

to your .mc file and recreate .cf, move the file in config and restart sendmail. Then it will also masquarade root :) you won't need to change the name with -f
:)
dunno if you have tried this exposed_user thing ?
> dunno if you have tried this exposed_user thing ?

Yes, I commented out the EXPOSED_USER line and was able to send mails when logged in as root.

See my post at 10/31/2006 03:08PM GMT :)
ok :) when you've asked for sendmail envelope masquarading I had thought that you were trying to circumvent root exposure thing :) I'm happy hat you are ok with that :))
Cheers,
K.