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

I'm using the perl code on my windows site. (visual basic) I'm trying to send an email with the following. Apparantely sendmail isn't available. I was told by my webhost that hmail was available. I just want to use SMTP to fire off some emails:

use strict; use warnings; use Email::Sender::Simple qw(sendmail); use Email::Simple; use Email::Simple::Creator; use Email::Sender::Transport::SMTP; my $email = Email::Simple->create( header => [ To => 'sking@adomain.com.com', From => 'admin@mydomain.com', Subject => "sample message", ], body => "Greetings,\nTyped message (content)\nGoodbye.\n", ); my $transport = Email::Sender::Transport::SMTP->new({ host => 'mail.mydomain.com', sasl_username => 'admin@mpros.com', sasl_password => '**', }); sendmail($email, { transport => $transport }); exit;
Can someone please help with this?

Replies are listed 'Best First'.
Re: SMTP mail not working for me
by Anonymous Monk on Jan 13, 2012 at 03:56 UTC

    Can someone please help with this?

    So what happens?

    What happens when you turn on debugging?

      Hi. I add my use CGI::Carp qw(fatalsToBrowser); and I got: Can't locate Net/SMTP_auth.pm in @INC (@INC contains: C:/Perl64/site/lib C:/Perl64/lib .) at C:\HostingSpaces\zlinkexc\mortgagerefinancingpros.com\wwwroot\cgi-bin\smtp2.cgi line 5. BEGIN failed--compilation aborted at C:\HostingSpaces\zlinkexc\mortgagerefinancingpros.com\wwwroot\cgi-bin\smtp2.cgi line 5. For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
      !C:\Perl\bin\perl.exe -w use CGI::Carp qw(fatalsToBrowser); use Net::SMTP_auth; $smtpserver = 'mail.mortgagerefinancingpros.com'; my $ServerAccount = "admin\@mortgagerefinancingpros.com"; my $ServerPwd = "pianos78997"; my $smtp = Net::SMTP->new($smtpserver, Hello => "mortgagerefinancingpr +os.com", Debug + => 1); $smtp->auth('CRAM-MD5', '$ServerAccount', '$ServerPwd'); $recipient = 'admin@mortgage-pros.com' ; $from = 'admin@mortgagerefinancingpros.com' ; #$smtp = Net::SMTP->new('', Timeout => 60, Debug => 1); ## smtp server requires authentication #$smtp->auth('admin@mortgagerefinancingpros.com','pianos78997'); $smtp->mail($from); $smtp->to($recipient); $smtp->data(); $smtp->datasend("To: $recipient\n"); $smtp->datasend("Subject: test message\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit;

        The error message means you need to install Net::SMTP_auth. In addition:

        my $smtp = Net::SMTP->new( ... );

        ... should probably be instead:

        my $smtp = Net::SMTP_auth->new( ... );

        ... and you almost certainly don't need the single quotes in:

        $smtp->auth('CRAM-MD5', '$ServerAccount', '$ServerPwd');

        ... if you want the values of the variables, and not the literal strings.


        Improve your skills with Modern Perl: the free book.