LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sending mail through sendmail (https://www.linuxquestions.org/questions/linux-newbie-8/sending-mail-through-sendmail-768169/)

vinaytp 11-10-2009 07:30 AM

sending mail through sendmail
 
Hi all...

I have to send mail from my linux machine to our company email server..I am planing to configure a sendmail server for that locally in my machine...

I have to write a script that should run a cron job once in 10 minutes that will check for particular keyword in /var/log/message file and send email to my office email id...

How can i best accomplish...Any suggestions....Pls

Awaiting for positive replys...

Any help will be appreciated...

Thanks in advance.....

centosboy 11-10-2009 07:47 AM

Quote:

Originally Posted by vinaytp (Post 3751545)
Hi all...

I have to send mail from my linux machine to our company email server..I am planing to configure a sendmail server for that locally in my machine...

I have to write a script that should run a cron job once in 10 minutes that will check for particular keyword in /var/log/message file and send email to my office email id...

How can i best accomplish...Any suggestions....Pls

Awaiting for positive replys...

Any help will be appreciated...

Thanks in advance.....


I think a better option would be a script that tails the message log and emails you when it finds and instance of the keyword??
better still there are apps that can do this for you. once called swatch and logging software called syslog-ng - which replaces the normal syslog software

cs24 11-10-2009 08:00 AM

It's not necessary to confige a sendmail to send mail to company email server.There are some script which can send mail by SMTP server.I can give you some example about send mail script .but you need to writing the script to "check for particular keyword in /var/log/message file"
Code:

#!/usr/bin/perl -w
use Net::SMTP_auth;
use Time::Local;
use Sys::Hostname;

$username='abc';
$password='abc';
$smtp = Net::SMTP->new('domainname',Hello =>'domainname');
$smtp->auth($username,$password);
$smtp->mail('abc@domainname');
$smtp->to('abc@gmail.com');
$smtp->data();
$smtp->datasend("hello world ! \n");
$smtp->quit;


chrism01 11-10-2009 06:34 PM

The Perl module for tailing a file is http://search.cpan.org/~mgrabnar/Fil...0.99.3/Tail.pm

HTH

vinaytp 11-11-2009 12:12 AM

Quote:

Originally Posted by cs24 (Post 3751579)
It's not necessary to confige a sendmail to send mail to company email server.There are some script which can send mail by SMTP server.I can give you some example about send mail script .but you need to writing the script to "check for particular keyword in /var/log/message file"
Code:

#!/usr/bin/perl -w
use Net::SMTP_auth;
use Time::Local;
use Sys::Hostname;

$username='abc';
$password='abc';
$smtp = Net::SMTP->new('domainname',Hello =>'domainname');
$smtp->auth($username,$password);
$smtp->mail('abc@domainname');
$smtp->to('abc@gmail.com');
$smtp->data();
$smtp->datasend("hello world ! \n");
$smtp->quit;


Hi cs24

I am trying with this...but i am getting following error

Can't locate Net/SMTP_auth.pm in @INC...

Can you pls tell me whats the module i need to install for smtp to work...

cs24 11-11-2009 02:24 AM

oh.sorry about that .I forgot I had installed the module .the module is "Net-SMTP_auth-0.08.tar.gz".may be you can download from some sites .

vinaytp 11-11-2009 02:31 AM

Quote:

Originally Posted by cs24 (Post 3752596)
oh.sorry about that .I forgot I had installed the module .the module is "Net-SMTP_auth-0.08.tar.gz".may be you can download from some sites .

Many Many Thanks cs24...

Code:

#!/usr/bin/perl -w
use Net::SMTP_auth;
use Time::Local;
use Sys::Hostname;
#
#$username='abc';
#$password='abc';
$smtp = Net::SMTP->new('linux.com',Hello =>'linux.com');
#$smtp->auth($username,$password);
$smtp->mail('vinay@vinay.linux.com');
$smtp->to('vinay@vinay.linux.com');
$smtp->data();
$smtp->datasend("hello world ! \n");
$smtp->quit;

This code is executing fine...But i am not able to receive any mail...my smtp port 25 is open..also dns is running and able to ping vinay.linux.com

Code:

nmap localhost
PORT    STATE SERVICE
21/tcp  open  ftp
22/tcp  open  ssh
25/tcp  open  smtp

Pls help me....

cs24 11-11-2009 02:49 AM

I telnet the vinay.linux.com 25 port it's not open .maybe the mailserver is your private mailserver.anyway ,you need to test the vinay.linux.com domain can send mail.you may be send a mail by the normal client ,like outlook. to test the vinay.linux.com is fine.
and maybe the
Code:

$smtp = Net::SMTP->new('linux.com',Hello =>'linux.com');
linux.com can replace by vinay.linux.com to try again.

chrism01 11-11-2009 07:14 PM

Are you trying to recv mail on localhost or your eth0 IP?
By default at install, sendmail only listens on localhost (127.0.0.1).
http://www.linuxtopia.org/online_boo...l-mta-sendmail


All times are GMT -5. The time now is 09:50 AM.