$mailprog Flags change in NMS Formail Script from "-oi -t" to "-f"

Hello, hope someone can help as I’ve been tearing my hair out with this one.

I’ve been using Matts Script Archive Formail for many years without any problem and have always been able to make tweaks to code using the ‘ReadMe’ file and a bit of search engine work, however I’m drawing a blank on a particular issue and I have a very limited understanding of Perl!

A new site I’m producing is being hosted on a server that asks for the following:

Within the script, the mail program used for sending mail is /usr/lib/sendmail . You should not use this with the -t argument (which find the From and To in the email) but use -f ‘from-email-address’ ‘to-email-address’ in place of the -t argument.

So I have upgraded to the NMS Formail script for the debugging and extra features and I have spent the evening trying to get it to work with the -f flag/argument

I’ve removed my previously trusted “-oi -t” and tweaked it as follows:

$mailprog = ‘/usr/lib/sendmail -f name@domain.co.uk name@domain.co.uk’;

This ‘kind of’ works, in that it sends a message from name@domain.co.uk to name@domain.co.uk (believe me this took me ages to work out!)

However I obviously need to replace the ‘name@domain.co.uk’ for the actual sender and recipient, and this is where I get stuck!

My assumption is that I just need to replace the ‘name@domain.co.uk’ with variables defined in the formail script, but I’m afraid I don’t understand enough to work this out and all my attempts so far have failed!

I’d hoped something like this would work:

$mailprog = ‘/usr/lib/sendmail -f $from $to’;

…but nope :frowning:

If anyone can advise I would be very grateful.

Robert

PS I can paste in the code from the NMS Formail Script if required - I’ve assumed that folks here are familiar with it?

I’m not able to paste in the script due to it being too long, but could paste over a couple of posts if it would help?

Otherwise the script can be found here http://nms-cgi.sourceforge.net/formmail_compat-3.14c1/FormMail.pl

I’m not familiar with Not Matt’s Scripts (it’s a great idea but I dunno if people are still paying attention to it), but I think it’s as simple as, you want variable interpolation inside a string (that those variables get turned into their actual values when that string is read). I believe " (double quotes) allow variable interpolation, though they’re not the only way.


$mailprog = "/usr/lib/sendmail -f $from $to";

Perlmonks.org is a good place for Perl questions. They’ll send you to the various documentation but it’s lively and you get reactions quickly. : )

Thanks Stomme Poes, I will give that a go and head over to PerlMonks if it doesn’t work.

Thanks for taking the time to reply, it’s appreciated.

At the moment I’m using a workaround of hosting the script on my server space rather than the clients, but I would still like to get this working properly with the -f.

Hi Guys,

Thanks for the replies, I tried all the suggestions on the forums but unfortunately I didn’t get anywhere with them. It’s not to say any were wrong, but it turns out that the issue went a little further than just the $mailprog line.

After some fantastic assistance from Dave Cross at NMS the solution with the -f flag is:

  $mailprog	= 	'/usr/lib/sendmail -f @recipients';

However it also needed a tweak to the code further along. I’ve pasted below Dave’s email in case anyone else needs to make the same change in the future.

[COLOR=“#0000CD”][INDENT][I]Looks to me like you’re on the right lines. But you have a couple of problems.

Firstly, the recipients aren’t known when we are setting the $mailprog variable, so you can’t make your changes there.

You need to make the change in the email_start() function that actually makes the connection to sendmail. That starts on line 591 of the version I’m looking at - but you might be looking at a different version with different line numbers.

In there we create an variable, $command, which contains the sendmail command line we are going to use. And the function knows the list of recipients - they are in an array called @recipients.

There’s a line that adds the postmaster address to the command. It looks like this:

 $command .= qq{ -f "$postmaster"} if $postmaster;

If think that all we need to do is to add the recipients on the line after that.

$command .= ' ' . join ' ', @recipients;

[/I][/INDENT][/COLOR]

Thanks again

Rob

Great! Very glad to hear you got in touch with Dave.

As an aside, he just gave a talk at the recent Perl conference. Unfortunately videos aren’t up yet, but the slides are.
http://act.yapc.eu/ye2013/talk/4506

slides:

In there he mentions that while they were hoping to get a not-so-terrible alternative to Matt’s Script Archive out there (the nms), it’s also not considered all that great, because it’s constrained by the same things that constrain Matt’s scripts: assumption of no libraries, no CPAN, nothing good. Now there’s serious talk of removing the old, slow, insecure CGI.pm from Perl 5 core. This would mean when those cheap hosting servers finally upgrade to the version of Perl that no longer carries that, scripts like Matt’s and nms will break. Possibly for the better though.

(the examples posted in Dave’s slides are also not necessarily best-written Perl either, but is supposed to be easier to read for newbies with redundancy).

Thanks for that. Just wizzed through the slides!

I’ve only just found out about NMS; feel like I’m sat in a time warp - one day I’ll catch up with best practice :wink:

Not sure how well the slides bring it over, but the reason for the ancient Perl is pretty much due to how (cheap) hosters work. Most of them may already have some old version of Perl installed, just as they usually have PHP installed too. But with PHP, everything is all together: you can take some server’s version of PHP and write your whole web app/site and it can all just run there.

Other languages like Perl, Python, Ruby, etc have libraries and modules that are usually imported/installed if your program needs it. Hosters don’t like giving customers root access or even good control over the wwwdata user (or whatever they have) who needs to run things, making trying to run those languages a much bigger pain in the ass.

Once cgi.pm is gone, Perl will just not be able to run in that way PHP does, and most Perl users have moved on from the Common Gateway Interface to WSGI (Web Server Gateway Interface), of which PSGI is the Perl version of.

Check out the slides from Miyagawa about the differences http://assets.en.oreilly.com/1/event/45/Plack_%20State%20of%20the%20Art%20Web%20Framework%20Superglue%20Presentation.pdf (a pdf, the visuals start around slide 13).

BTW if you are looking to meet up with Perl people near you, there’s some PerlMongers groups in the UK, the biggest probably being london.pm (of which Dave’s a member). There are also Perl Workshops, which are nice one-day things. Next London Perl Workshop is 30 novemeber.