Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by Corion (Patriarch)
on Nov 30, 2015 at 15:49 UTC ( [id://1148908]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: smtp authentication in perl script for contact form
by Anonymous Monk on Dec 01, 2015 at 12:48 UTC
    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://1148908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-23 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found