Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Configure MTA on CentOS (RHEL)

Posted on 2006-10-26
24
Medium Priority
?
1,997 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:damieneowen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 7
24 Comments
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17818480
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)



0
 
LVL 14

Assisted Solution

by:ygoutham
ygoutham earned 300 total points
ID: 17818588
do a

rpm -qa | grep sendmail

 to see if sendmail is installed or postfix if that is installed (replace sendmail with postfix).

if the system gives a message back with sendmail-3.x.x. then you know that sendmail is there and same for postfix.

then you can always try

sendmail -i user@host.com < /some/text/file.txt to see if the mail goes out.

if not check the /etc/mail/sendmail.mc file to remove relaying to the internet comment (the file is descriptive enuf)

goutham
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17818596
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
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:damieneowen
ID: 17833085
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
);
0
 
LVL 30

Accepted Solution

by:
Kerem ERSOY earned 1200 total points
ID: 17833240
Ok,  sendmail comes bind only to the loopback interface. So since it is connected to loopback interface when it does a query it gets your hostname as caesar.localhomain from your hosts file.

You can either define sendmail to bind to your ethernet connection or you can use domain masquarading.

Yo comment out this from the m4 file:

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

By default snemail is listenin only the localhost interface.

The eror you got from damieno@sandyxsystems.co.uk means that before acepting e-mail from you the sandsystems.co.uk SMTP server wanted to query your domain if it is resolvable. but since it got caesear.localdomain as the tmian it could not resolve your domain and rejected to accept mail from a host wh does not have a formal domain address. To avod this you can add a domain masquarading entry to your .m4 file such as this:


LOCAL_DOMAIN(`host.mydomain.com')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 #
dnl MASQUERADE_AS(`mydomain.com')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.mydomain.com)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
MAILER(smtp)dnl


Cheers,
K.


0
 

Author Comment

by:damieneowen
ID: 17833940
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
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17839885
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
0
 

Author Comment

by:damieneowen
ID: 17841309
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
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17841346
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
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17841381
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.
0
 

Author Comment

by:damieneowen
ID: 17841528
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.
0
 

Author Comment

by:damieneowen
ID: 17841538
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
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17841599
Hi,

Masquarading does not work for some users like root.
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17841631
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
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17841641
read last post like

once all this is done do a "m4 ...", "make", "service..."
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17841705
remove

EXPOSED_USER(`root')


from your .m4 filr this will inhibit root not translated..
0
 

Author Comment

by:damieneowen
ID: 17841882
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?
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17841988
congrats!!!!
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17842038
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.
0
 

Author Comment

by:damieneowen
ID: 17842451
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?
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17842739
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:

http://www.experts-exchange.com/Programming/Programming_Platforms/Unix_Programming/Q_20852113.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
:)
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17843583
dunno if you have tried this exposed_user thing ?
0
 

Author Comment

by:damieneowen
ID: 17843757
> 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 :)
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 17843856
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.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question