Jump to content

Using Postfix vice Sendmail for Guestbook notification ??


Relic2K
 Share

Recommended Posts

Whould you please explain your problem a little bit more?

what error are you getting?

what should that perl program do?

Does it need to run sendmail, but it can't find it? or what?

 

Postfix's sendmail is at /usr/sbin/

 

help us to help you ;)

Link to comment
Share on other sites

well I know matt's script is perl not php.

but with php it would look something like this

<?

$sql = "insert into $table (id, name, text, ..... {other fields here}) value ($id, $name, $text ....{other fields})";

if(mysql_query($sql))

  mail("me@me.com","You have a new message","posted by $namenn$text");

 

or something like that anyway :roll:

Link to comment
Share on other sites

Whould you please explain your problem a little bit more?  

what error are you getting?  

what should that perl program do?  

Does it need to run sendmail, but it can't find it? or what?

 

Postfix's sendmail is at /usr/sbin/

 

help us to help you ;)

 

Here is snippet of the code which uses sendmail. Yes it is a perl script "guestbook" for web sites.

You can setup the option to email you when someone enters something in the guestbook, using sendmail. But I wanted to use Postfix because know it is working using LogSentry (aka logcheck)

which goes through the log files, snort logs, and emails them to me locally.

 

**************************************************************

# Set Your Options:

$mail = 1; # 1 = Yes; 0 = No

$uselog = 1; # 1 = Yes; 0 = No

$linkmail = 1; # 1 = Yes; 0 = No

$separator = 1; # 1 = <hr>; 0 = <p>

$redirection = 0; # 1 = Yes; 0 = No

$entry_order = 1; # 1 = Newest entries added first;

# 0 = Newest Entries added last.

$remote_mail = 0; # 1 = Yes; 0 = No

$allow_html = 1; # 1 = Yes; 0 = No

$line_breaks = 0; # 1 = Yes; 0 = No

 

# If you answered 1 to $mail or $remote_mail you will need to fill out

# these variables below:

$mailprog = '/usr/sbin/postfix';

$recipient = 'me@me.local.comt';

 

********************************************************************************

*

#########

# Options

 

# Mail Option

if ($mail eq '1') {

open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!n";

 

print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})n";

print MAIL "From: $FORM{'username'} ($FORM{'realname'})n";

print MAIL "Subject: Entry to Guestbooknn";

print MAIL "You have a new entry in your guestbook:nn";

print MAIL "------------------------------------------------------n";

print MAIL "$FORM{'comments'}n";

print MAIL "$FORM{'realname'}";

 

if ( $FORM{'username'} ){

print MAIL " <$FORM{'username'}>";

}

 

print MAIL "n";

 

if ( $FORM{'city'} ){

print MAIL "$FORM{'city'},";

}

 

if ( $FORM{'state'} ){

print MAIL " $FORM{'state'}";

}

 

if ( $FORM{'country'} ){

print MAIL " $FORM{'country'}";

}

 

print MAIL " - $daten";

print MAIL "------------------------------------------------------n";

 

close (MAIL);

}

 

if ($remote_mail eq '1' && $FORM{'username'}) {

open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!n";

 

print MAIL "To: $FORM{'username'}n";

print MAIL "From: $recipientn";

print MAIL "Subject: Entry to Guestbooknn";

print MAIL "Thank you for adding to my guestbook.nn";

print MAIL "------------------------------------------------------n";

print MAIL "$FORM{'comments'}n";

print MAIL "$FORM{'realname'}";

 

if ( $FORM{'username'} ){

print MAIL " <$FORM{'username'}>";

}

print MAIL "n";

 

if ( $FORM{'city'} ){

print MAIL "$FORM{'city'},";

}

 

if ( $FORM{'state'} ){

print MAIL " $FORM{'state'}";

}

 

if ( $FORM{'country'} ){

print MAIL " $FORM{'country'}";

}

 

print MAIL " - $daten";

print MAIL "------------------------------------------------------n";

 

close (MAIL);

}

Link to comment
Share on other sites

I guess that the problem is because you are using "postfix" directly instead of postfix's sendmail clone (/usr/sbin/sendmail); So lets test:

 

# foo.pl

# Perl test script

$mailprog = '/usr/sbin/postfix';

$recipient = 'aru@localhost';  



# Mail Option 

open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!n";



print MAIL "From: foo@nodomain.orgn";

print MAIL "Subject: Entry to Guestbooknn";

print MAIL "You have a new entry in your guestbook:nn";

print MAIL "------------------------------------------------------n";

print MAIL "Foo commentn";

print MAIL "Bar opinion";

print MAIL "n";

Disclaimer: I don't know perl, so I've just stripped out those parts that seemed to me that are not needed to the test :P

 

Let's test

~$ perl foo.pl

postfix: error: to submit mail, use the Postfix sendmail command

postfix: fatal: the postfix command is reserved for the superuser

Now lets use /usr/sbin/sendmail instead of /usr/sbin/postfix:

~$ perl foo.pl 

~$

Let's see if I have new mail

~$ correo 

correo, ver: 3.1

aru, tienes 1 mensajes!



Mensaje nº 1

       Entry to Guestbook de <foo@nodomain.org>

 

That's it! replace

$mailprog = '/usr/sbin/postfix';

with

$mailprog = '/usr/sbin/sendmail';

 

HTH <-- This has been my first attempt to hack a perl script :cool: :P

Link to comment
Share on other sites

I have already switched from sendmail to postfix, because I know it is already running and working. That is what I am trying to do. Get notifications via Postfix instead of Sendmail. But neither seem to be working properly. I did email Matt as well about this, but I have not got a reply back yet.

Link to comment
Share on other sites

I don't know if I've made myself clear, if you have postfix installed (like me) you must have a "/usr/sbin/sendmail" program (from the postfix package) which is there to deal with emails mailed using the old "sendmail" interface (don't confuse sendmail package with postfix's sendmail interface).

 

The perl script does something like this:

echo "message" | $mailprog you@yourdomain

 

so since /usr/sbin/postfix (the postfix control program, and which seems to be used by your perl script) doesn't work THAT WAY (the sendmail way), you should use the sendmail *clone* that comes with postfix (/usr/sbin/sendmail) which implements the same interface that uses the ORIGINAL sendmail program, thus allowing you to use that way (pipe from stdin) for sending messages.

 

Test this yourself (using postfix's sendmail), if it works then you only need to change "/usr/sbin/postfix" with "/usr/sbin/sendmail" inside your script:

 

~$ echo "To: $USER

> Subject: Testing postfix mailer

> 

> I'm testing postfix from commandline using a pipe.

> " | /usr/sbin/sendmail $USER

~$ 

You have new mail in /var/spool/mail/aru

~$

 

The original perl script is wrong, at least for Mandrake distros, where /usr/sbin/postfix is the program that controls the mailer system, so you can't send messages from stdin using postfix directly. You should use the postfix's sendmail interface.

 

check "man postfix" and "man sendmail" for further explanations

 

For Example: quoted from postfix's sendmail man page:

NAME

      sendmail - Postfix to Sendmail compatibility interface

[...]

DESCRIPTION

      The  sendmail  program  implements the Postfix to Sendmail

      compatibility interface.  For the  sake  of  compatibility

      with  existing  applications,  some  Sendmail command-line

      options are recognized but silently ignored.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...