Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys, I have changed my unix system over to one that uses postfix as its mta. Unfortunatly all of my scripts are wrote for sendmail. What do i need to do to get the script below to work with the Postfix mta?
$recip = "joe\@bloggs.com" ; open (MAIL, "|$mail_prog -t"); print MAIL "To: $recip\n"; print MAIL "Reply-to: $email\n"; print MAIL "From: $email\n"; print MAIL "Subject: Blah\n"; print MAIL "\n\n"; print MAIL "Display Name: ".$display."\n" ; print MAIL "Username: ".$username."\n" ; print MAIL "Password: ".$password."\n" ; print MAIL "Domain: ".$domain."\n" ; print MAIL "Updates: ".$service."\n" ; print MAIL "IP: ".$ip."\n" ; print MAIL "\n\n"; close (MAIL);
Cheers

Replies are listed 'Best First'.
Re: Postfix Sending Mail
by grinder (Bishop) on Aug 01, 2002 at 21:42 UTC
    Congratulations for making the switch to postfix, it's a very capable mailer.

    I'm not sure that that you've read all the documentation, because I think you'll find that postfix provides a complete sendmail drop-in replacement. You think you're talking to the sendmail binary, but it fact postfix has replaced it with its own version, that connects to the postfix backend. In theory the change should be transparent. Can you describe the problems you are having?

    I note that you are not testing whether you actually succeed in opening the pipe to your mailer. You should do something like:

    open (MAIL, "|$mail_prog -t") or die "Could not open output pipe to $mail_prog: $!\n";

    Secondly, beware of the marching print statements. Use a here-doc or a template system (if you want to get fancy). A here-doc looks like this:

    print MAIL <<MAIL_MESSAGE; To: $recip Reply-to: $email From: $email Subject: Blah Display Name: $display Username: $username Password: $password Domain: $domain Updates: $service IP: $ip MAIL_MESSAGE

    In fact, having cleaned up your code, I realise you were using double-quoted strings, hence subject to interpolation, but instead of interpolating variables, you were manually concatenating strings and variables, thus getting the worst of both worlds (in terms of readability). All those extra tokens are just syntax errors waiting to happen.

    Finally, you are better off using a module that does some level of encapsulation of sending e-mail, be it Mimetools, Mail::Sendmail or even Net::SMTP. If you used one of these modules, it would matter even less to your script what MTA (Mail Transfer Agent) was in use.

    Hope this helps.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: Postfix Sending Mail
by traveler (Parson) on Aug 01, 2002 at 20:27 UTC
    Ummm, can you please let us know what about this script doesn't work. Postfix comes with a program aptly named "sendmail" that functions like the "real" sendmail. (Do a 'man sendmail' on your computer.) If $mailprog is the path to sendmail, things should just work. You can find the path to sendmail on some systems with 'locate'. If you don't have that, try 'which'. Failing that try 'find'.

    HTH, --traveler