Link to home
Start Free TrialLog in
Avatar of MuddyMojo
MuddyMojo

asked on

Linux | Red Hat | sendmail Local Script Access

I setup a new install of RH Fedora. What, if any, mods are needed to allow me to write scripts locally and send from this server? I have a small script that creates a single email message. When I execute it there are no errors but I also never get a email in my inbox (external account). Any suggestions? I will up the point as needed.
Avatar of ircpamanager
ircpamanager

what does your mailog say. type cat /var/log/maillog at prmpt and post your results.
Avatar of MuddyMojo

ASKER

"Connection timed out with domain.com"

domain.com is my corporate mail server (Exchange). Maybe a DNS issue?
I changed DNS to another set... Now log says "sent" and "delivery accepted" but still nothing in Inbox or Spam folder.
Opps... Doesn't say "Delivery accepted"... Says "Message accepted for delivery" in case that matters.
what command are you using to send your email
#!/usr/bin/perl

my $to = "myname\@mydomain.com";
my $from = "myname\@mydomain.com";
my $subject = "Test Message";

open(MAIL,"|/usr/lib/sendmail -t -oi") or die "sendmail error\n";

print MAIL <<END_OF_MESSAGE;
To: $to
From: $from
Subject: $subject

This is a test message.
END_OF_MESSAGE

close MAIL;
you could try to download Mail::Sendmail module from CPAN. Then try this script:

#!/usr/bin/perl -w

use Mail::Sendmail;

  %mail = ( To      => 'you@domain.org',
            From    => 'someone@domain.org',
            Message => "This is a very short message"
           );

  sendmail(%mail) or die $Mail::Sendmail::error;

  print "OK. Log says:\n", $Mail::Sendmail::log;
I just double checked on a RedHat EL4 box with sendmail installed and running, and the script I gave you works.
Trying...
If I use EXACTLY what you wrote I get a "can't locate Mail/Sendmail.pm in @INC
did you install Mail::Sendmail module from CPAN?
Oops... My bad. I took it as you tried the above on a RH box "as is". Will try the install.
you can get it from CPAN
So no-go on using the sendmail that came with the OS?
Couple of things to check (assuming the host name of the exchange server is "exchange" and IP 192.168.10.1:

0) Is your exchange server on the same network as you?  Can you "ping exchange" or "ping 192.168.10.1"?

1) Is your exchange server accepting smtp mail?  It seems like it, but try "telnet 192.168.10.1 25" from the redhat box and make sure you get a welcome message.  Exchange doesn't use/enable smtp by default.

2) type "mail -v -s test me@mydomain.com" and you should see a conversation going on with sendmail.  That's a good sign that at least the local system is accepting the message.

Check your /etc/sendmail.cf file and look for a line that begins with DS - this specifies your "smart host".  That's the place where sendmail punts all mail to when it doesn't know what else to do with.  Setting that to the name or IP address of your exchange server (if it's not already) and reloading sendmail may help.  e.g.

DS192.168.10.1

Hth,
Ian
0) Is your exchange server on the same network as you?  Can you "ping exchange" or "ping 192.168.10.1"?
A>> Same network. PING works.

1) Is your exchange server accepting smtp mail?  It seems like it, but try "telnet 192.168.10.1 25" from the redhat box and make sure you get a welcome message.  Exchange doesn't use/enable smtp by default.
A>> Yes. Telnet connects and returns a response to "helo".

2) type "mail -v -s test me@mydomain.com" and you should see a conversation going on with sendmail.  That's a good sign that at least the local system is accepting the message.
A>> This one said unrecognized command. I am going to test one using my gmail account just for kicks.
"So no-go on using the sendmail that came with the OS?" Did the example I gave you work?
What happens when you do

$sendmail me@mydomain.com
Subject: test

testing from sendmail
.

?

And can you post the last page or so of /var/log/mail.log?
Question: Windows has a directory called Pickup where you can put properly formatted ascii files which get converted and sent by SMTP... Does Linux have a similar directory?

I've been swamped so I'm just getting back to this. Sorry for the delay. I'm trying the last couple of suggestions now.
Linux does not have a directory like that, at least not that I am aware. What happen with the perl module?
Sorry I've been away for so long... Multiple reasons. Bummer on the directory. I am going to reinstall TODAY and try things tomorrow. I will let you all know if it works or I get stuck again. Thanks for puting up with me!!!
ircpamanager...

I finally finished the new Red Hat install and will be testing using your example today. I am crossing my fingers!!!
Could I get a simple example of a sendmail script... Really basic for testing. I want to make sure I test this correctly using native sendmail. Thank you all for your input and support!!!
ASKER CERTIFIED SOLUTION
Avatar of ircpamanager
ircpamanager

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
When I run the above script as root it goes to the next line. No error, but no email (TO and FROM are my valid email address). Something I can check?
silly question did you replace all the fake info with your own?  Do you have Selinux enabled. Also is this box on a network with other pc's
ircpamanager,

+ Changed TO and FROM to my email address.
+ SE Linux enabled
+ On my corporate LAN with other computers/servers. Exchange server on the same network.

Thanks for you help - I know this has been a long process - It's appreciated!!!
Here is a screenshot of the file "test" and also what happens when I type test at the prompt...

[blannan@blannan ~]$
[blannan@blannan ~]$
[blannan@blannan ~]$ more test
#!/usr/bin/perl

unless(open (MAIL, "|/usr/sbin/sendmail -t")) {
print "error.\n";
warn "Error starting sendmail: $!";
}
else{
print MAIL "From: blannan\@potpourrigroup.com\n";
print MAIL "To: blannan\@potpourrigroup.com\n";
print MAIL "Subject: test subject\n\n";
print MAIL "test mail message";
close(MAIL) || warn "Error closing mail: $!";
print "Mail sent.\n";
}
[blannan@blannan ~]$
[blannan@blannan ~]$
[blannan@blannan ~]$ test
[blannan@blannan ~]$
[blannan@blannan ~]$
[blannan@blannan ~]$  
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
Did a chmod 777 on the file and tried it again...

When I type the script name and hit enter it pauses for a moment and then says "Mail sent." but nothing in my inbox yet. Nothing in Spam folder either. Hmmmm...
Not sure how to disable SELinux...
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
Disabled SELinux... The program now runs super fast. However, no email in my inbox :o(

I will try cpan...
OK - I disabled SE and then enabled it. Now it works. I can send to everything but my Exchange server but that's not a Linux issue. Thank you, thank you, thank you for all your help. I know it was a long run!
no problem, had a feeling it was that. Have fun making exchange relay for sendmail.
see ya.