Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: smtp authentication in perl script for contact form

by Anonymous Monk
on Nov 30, 2015 at 15:35 UTC ( [id://1148905]=note: print w/replies, xml ) Need Help??


in reply to Re: smtp authentication in perl script for contact form
in thread smtp authentication in perl script for contact form

Hello Corion,

Thanks for your input!
I have repaced the double quotes for the single quotes as you recommended aswell as the use strict; and use warnings; to get to the quick fix, but then I get a 500 internal server error.

But I think it is better to concentrate on a good script as you suggested then to continue using current script with a huge open gate.

Therefore I followed your link and used TFMail Autoinstall to install the script onto the server.
When I run the script I get the error:

Application Error

An error has occurred in the program

SMTP command RCPT TO:<xxxx@xxxx.com> gave response [554 5.7.1 <firewall.vhosting.namehost.com11.222.68.68>: Client host rejected: Access denied ] at /home/vhosting/z/vhost0028581/domains/xxxx.com/htdocs/www/cgi-bin/websiteformulier.cgi line 967, <GEN1> line 4.


I think the error occurs because the host needs SMTP Authentication? E.g. I did not give SMTP_PORT, SSL="OFF", username / password.

Would that not be necessary?br>
BR
Olaf

  • Comment on Re^2: smtp authentication in perl script for contact form

Replies are listed 'Best First'.
Re^3: smtp authentication in perl script for contact form
by Corion (Patriarch) on Nov 30, 2015 at 15:49 UTC

    I don't know about the vhost and firewall setup of your hosting provider.

    Most likely, a fix is to set up the mail program correctly:

    $mailprog = '/usr/lib/sendmail -oi -t';

    If you set the variable to smtp:xxx, this error is your ISP telling you that they don't allow direct SMTP connections, most likely for spam reasons.

      Hi Corion,
      I have asked them and they replied:

      Outgoing mail server: smtp.mail.hostname.com
      port for outgoing mail: 587
      SSL: Disabled
      Authentication Through e-mail address and password

      (sendmail as mailprog does not work)
      I did tried the sendmail option before i asked them as you suggested and script works but e-mail is not send. Browser shows the ok page.

        Hmm - it doesn't seem as if the NMS form mailer supports authentication.

        Looking at Mail::Sender, it doesn't seem too hard to add at least PLAIN and LOGIN authentication to the script, but I have too many projects on my plate already to also start working on the nms-cgi scripts.

        The relevant code in Mail::Sender is:

        sub Mail::Sender::Auth::LOGIN { my $self = shift(); my $s = $self->{'socket'}; $_ = send_cmd $s, 'AUTH LOGIN'; if (!/^[123]/) { return $self->Error(INVALIDAUTH('LOGIN', $_)); } if ($self->{auth_encoded}) { # I assume the username and password had been base64 encoded a +lready! $_ = send_cmd $s, $self->{'authid'}; if (!/^[123]/) { return $self->Error(LOGINERROR($_)); } $_ = send_cmd $s, $self->{'authpwd'}; if (!/^[123]/) { return $self->Error(LOGINERROR($_)); } } else { $_ = send_cmd $s, &encode_base64($self->{'authid'}, ''); if (!/^[123]/) { return $self->Error(LOGINERROR($_)); } $_ = send_cmd $s, &encode_base64($self->{'authpwd'}, ''); if (!/^[123]/) { return $self->Error(LOGINERROR($_)); } } return; } sub Mail::Sender::Auth::PLAIN { my $self = shift(); my $s = $self->{'socket'}; $_ = send_cmd $s, "AUTH PLAIN"; if (!/^[123]/) { return $self->Error(INVALIDAUTH('PLAIN', $_)); } $_ = send_cmd $s, encode_base64("\000" . $self->{'authid'} . "\000 +" . $self->{'authpwd'}, ''); if (!/^[123]/) { return $self->Error(LOGINERROR($_)); } return; }

        ... so to make FormMail.pl always authenticate, you could try to rewrite the sub newmail in FormMail.pl as follows:

        sub newmail { my ($self, $scriptname, $sender, @recipients) = @_; $self->{Sock} = IO::Socket::INET->new($self->{Mailhost}); defined $self->{Sock} or die "connect to [$self->{Mailhost}]: $!"; my $banner = $self->_smtp_response; $banner =~ /^2/ or die "bad SMTP banner [$banner] from [$self->{Mail +host}]"; my $helohost = ($ENV{SERVER_NAME} =~ /^([\w\-\.]+)$/ ? $1 : '.'); $self->_smtp_command("HELO $helohost"); $self->_smtp_command("MAIL FROM:<$sender>"); # AUTH PLAIN support use MIME::Base64; # Crash immediately if the module is unavailable if( defined $auth_user and defined $auth_password ) { $self->_smtp_command("AUTH PLAIN"); $self->_smtp_command( encode_base64("\000" . $auth_user . "\000" . + $auth_password, '')); }; foreach my $r (@recipients) { $self->_smtp_command("RCPT TO:<$r>"); } $self->_smtp_command("DATA", '3'); $self->output_trace_headers($scriptname); }

        Note that the above code is completely untested. You will need to add $auth_user and $auth_password near the top of the script to the use vars qw(...) block and also set their values in the "USER CONFIGURATION SECTION".</c>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1148905]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-19 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found