Re: configuring Net::SMTP

2023-07-15 Thread perl
Many thanks to Bob, Olivier, Claude, and Andinus. I learned from all your 
comments, and I got the Net::SMTP working! 

Rick

> On Jul 9, 2023, at 8:03 AM, Bob Kardell  wrote:
> 
> One thing to check from experience - make sure hostgator does not block 
> outbound SMTP ports.  Many do to prevent spam.  I spent hours trying to 
> configure Net::SMTP on a different host only to discover the code was working 
> but the email was being blocked.   If hostgator received it it may be because 
> it was only a mailbox inside of hostgator.
> 
> Just a thought,
> 
> Bob 
> 
>> On Jul 8, 2023, at 8:52 PM, Claude Brown via beginners  
>> wrote:
>> 
>> Hi Rick,
>> 
>> We use Net::SMTP to send emails via SendGrid.  They require a user/pass 
>> authentication over SSL and I wonder if that is what is going wrong in your 
>> case.  The other thing worth doing is checking the return-value of each SMTP 
>> call as something may be going wrong silently.
>> 
>> Below is a fragment of our code that does (a) authentication and (b) checks 
>> each value.  I hope it assists.
>> 
>> Cheers,
>> 
>> Claude.
>> 
>> use strict;
>> use Carp;
>> use Net::SMTP;
>> 
>> use constant SMTP_HOST => 'smtp.sendgrid.net';
>> use constant SMTP_PORT => 465;
>> use constant SMTP_USER => 'the-username';
>> use constant SMTP_PASS => 'the-password';
>> use constant SMTP_TIMEOUT => 15;
>> use constant SMTP_DEBUG => 0;
>> 
>> my $smtp = Net::SMTP->new(
>>   Host => SMTP_HOST,
>>   Port => SMTP_PORT,
>>   Timeout => SMTP_TIMEOUT,
>>   SSL => 1,
>>   Debug => SMTP_DEBUG);
>> 
>> my $fromAddr = 'whowe...@somehwere.com';
>> my $toAddr = 'whoe...@somewhere.com';
>> my $theBody = 'the mail headers and body of the email';
>> 
>> $smtp->auth(SMTP_USER, SMTP_PASS) or confess "SMTP auth: " . 
>> $smtp->message();
>> $smtp->mail($fromAddr)or confess "SMTP mail: " . 
>> $smtp->message();
>> $smtp->to($toAddr)or confess "SMTP to: " . $smtp->message();
>> $smtp->data() or confess "SMTP data: " . 
>> $smtp->message();
>> $smtp->datasend($theBody) or confess "SMTP datasend: " . 
>> $smtp->message();
>> $smtp->dataend()  or confess "SMTP dataend: " . 
>> $smtp->message();
>> $smtp->quit() or confess "SMTP quit: " . 
>> $smtp->message(); 
>> --
>> Claude.
>> 
>> 
>> -Original Message-
>> From: p...@reason.net  
>> Sent: Sunday, July 9, 2023 10:41 AM
>> To: Perl Beginners 
>> Subject: Re: configuring Net::SMTP
>> 
>> CAUTION: This email originated from outside of the organization. Do not 
>> click links or open attachments unless you recognize the sender and know the 
>> content is safe.
>> 
>> Thanks, Andinus. This is useful information. — Rick
>> 
>>> On Jul 8, 2023, at 10:11 AM, Andinus  wrote:
>>> 
>>> 
>>> Hello Rick,
>>> 
>>> Hostgator might be able to provide you more information regarding why
>>> the email delivery is failing. I'm not very familiar with mail stuff.
>>> 
>>> You can also try NET::SMTP->new(Debug => 1) and send an email, it might
>>> provide useful info.
>>> 
>>> Maybe this answer on stackoverflow might be helpful
>>> https://stackoverflow.com/a/10008814
>>> 
>>> Have a good day!
>>> 
>>> Rick T @ 2023-07-08 08:37 -07:
>>> 
>>>> I have two subroutines (below) in a program that uses Net::SMTP. I’ve
>>>> recently moved my site from FutureQuest.net <http://futurequest.net/>
>>>> to Hostgator.com <http://hostgator.com/>, and this part of my program
>>>> has stopped working. The first routine sends an analysis of a test to
>>>> me at Reason.net <http://reason.net/>, and the second send a score to
>>>> several addresses associated with the student. On my new host at
>>>> Hostgator both fail to do this. (One of the “technicians” at Hostgator
>>>> said he found my email, so one or both likely arrived at
>>>> webmas...@hostgator.com <mailto:webmas...@hostgator.com>.)
>>>> 
>>>> I am not trained in computer tech; I’m just a 78 year old high school
>>>> teacher who bought a few books on perl, so I don’t really understand
>&

Re: configuring Net::SMTP

2023-07-09 Thread Bob Kardell via beginners
One thing to check from experience - make sure hostgator does not block 
outbound SMTP ports.  Many do to prevent spam.  I spent hours trying to 
configure Net::SMTP on a different host only to discover the code was working 
but the email was being blocked.   If hostgator received it it may be because 
it was only a mailbox inside of hostgator.

Just a thought,

Bob 

> On Jul 8, 2023, at 8:52 PM, Claude Brown via beginners  
> wrote:
> 
> Hi Rick,
> 
> We use Net::SMTP to send emails via SendGrid.  They require a user/pass 
> authentication over SSL and I wonder if that is what is going wrong in your 
> case.  The other thing worth doing is checking the return-value of each SMTP 
> call as something may be going wrong silently.
> 
> Below is a fragment of our code that does (a) authentication and (b) checks 
> each value.  I hope it assists.
> 
> Cheers,
> 
> Claude.
> 
> use strict;
> use Carp;
> use Net::SMTP;
> 
> use constant SMTP_HOST => 'smtp.sendgrid.net';
> use constant SMTP_PORT => 465;
> use constant SMTP_USER => 'the-username';
> use constant SMTP_PASS => 'the-password';
> use constant SMTP_TIMEOUT => 15;
> use constant SMTP_DEBUG => 0;
> 
> my $smtp = Net::SMTP->new(
>Host => SMTP_HOST,
>Port => SMTP_PORT,
>Timeout => SMTP_TIMEOUT,
>SSL => 1,
>Debug => SMTP_DEBUG);
> 
> my $fromAddr = 'whowe...@somehwere.com';
> my $toAddr = 'whoe...@somewhere.com';
> my $theBody = 'the mail headers and body of the email';
> 
> $smtp->auth(SMTP_USER, SMTP_PASS) or confess "SMTP auth: " . $smtp->message();
> $smtp->mail($fromAddr)or confess "SMTP mail: " . $smtp->message();
> $smtp->to($toAddr)or confess "SMTP to: " . $smtp->message();
> $smtp->data() or confess "SMTP data: " . $smtp->message();
> $smtp->datasend($theBody) or confess "SMTP datasend: " . 
> $smtp->message();
> $smtp->dataend()  or confess "SMTP dataend: " . 
> $smtp->message();
> $smtp->quit() or confess "SMTP quit: " . 
> $smtp->message(); 
> --
> Claude.
> 
> 
> -Original Message-
> From: p...@reason.net  
> Sent: Sunday, July 9, 2023 10:41 AM
> To: Perl Beginners 
> Subject: Re: configuring Net::SMTP
> 
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you recognize the sender and know the 
> content is safe.
> 
> Thanks, Andinus. This is useful information. — Rick
> 
>> On Jul 8, 2023, at 10:11 AM, Andinus  wrote:
>> 
>> 
>> Hello Rick,
>> 
>> Hostgator might be able to provide you more information regarding why
>> the email delivery is failing. I'm not very familiar with mail stuff.
>> 
>> You can also try NET::SMTP->new(Debug => 1) and send an email, it might
>> provide useful info.
>> 
>> Maybe this answer on stackoverflow might be helpful
>> https://stackoverflow.com/a/10008814
>> 
>> Have a good day!
>> 
>> Rick T @ 2023-07-08 08:37 -07:
>> 
>>> I have two subroutines (below) in a program that uses Net::SMTP. I’ve
>>> recently moved my site from FutureQuest.net <http://futurequest.net/>
>>> to Hostgator.com <http://hostgator.com/>, and this part of my program
>>> has stopped working. The first routine sends an analysis of a test to
>>> me at Reason.net <http://reason.net/>, and the second send a score to
>>> several addresses associated with the student. On my new host at
>>> Hostgator both fail to do this. (One of the “technicians” at Hostgator
>>> said he found my email, so one or both likely arrived at
>>> webmas...@hostgator.com <mailto:webmas...@hostgator.com>.)
>>> 
>>> I am not trained in computer tech; I’m just a 78 year old high school
>>> teacher who bought a few books on perl, so I don’t really understand
>>> how to fill in the many variable assignments that make up most of
>>> these two routines. Instead I took guesses and tried stuff to see
>>> what would happen. If any of you have suggestions or corrections, I’d
>>> be grateful!
>>> 
>>> Rick Triplett
>>> 
>>> FIRST SUBROUTINE:
>>> 
>>> sub email_analysis {# to LibertyLearning for score posting and analysis
>>>   my $n_max = shift;
>>>   my @analysis = define_analysis($n_max);
>>> 
>>>   my $subject_line
>>>   = "$pf{percent_correct_fin

Re: configuring Net::SMTP

2023-07-08 Thread Olivier
Rick T  writes:

> [1:text/plain Show]
>
>
> [2:text/html Hide Save:noname (4kB)]
>
> I have two subroutines (below) in a program that uses Net::SMTP.  I’ve
> recently moved my site from FutureQuest.net to Hostgator.com, and this part
> of my program has stopped working. The first routine sends an analysis of a
> test to me at Reason.net, and the second send a score to several addresses
> associated with the student. On my new host at Hostgator both fail to do
> this. (One of the “technicians” at Hostgator said he found my email, so one
> or both likely arrived at webmas...@hostgator.com.)
>
>  I am not trained in computer tech; I’m just a 78 year old high school
> teacher who bought a few books on perl, so I don’t really understand how to
> fill in the many variable assignments that make up most of these two
> routines. Instead I took guesses and tried stuff to see what would happen.
> If any of you have suggestions or corrections, I’d be grateful! 
>
> Rick Triplett
>
> FIRST SUBROUTINE:
>
> sub email_analysis {# to LibertyLearning for score posting and analysis
> my $n_max = shift;
> my @analysis = define_analysis($n_max);
>
> my $subject_line
> = "$pf{percent_correct_final} $pf{name_full} $course_file\n";
>
> # Send administration an email of statistical analysis
> my $to = 'socra...@reason.net';
> my $from = 'webmas...@libertylearning.com';   
> my $site = 'libertylearning.com';
> my $smtp_host = 'mail.libertylearning.com';

Are you sure that mail.libertylearning.com is a valid SMTP host? And can
you use it from your current Web host? Usually, one would use the
mailgateway from the Web hosting company.

Web host may limit outgoing email from any web site they host to prevent
scammer web sites: they can filter whatever email you send and make sure
you send legitimate stuff and you do not put their business in danger of
being classified as a scam friendly business.

Contact your Web host and ask them what mail gateway you should use to
have your web site send email.

Best regards,

Olivier

>
> my $smtp = Net::SMTP->new( $smtp_host, Hello => $site );
> $smtp->mail($from);
> $smtp->to($to);
> $smtp->data();
> $smtp->datasend("From: webmaster\@LibertyLearning.com\n");
> $smtp->datasend("To: $to\n"); 
> $smtp->datasend("Date: $pf{ date_ended }\n");
> $smtp->datasend("Subject: $subject_line\n");
> $smtp->datasend("\n");
> $smtp->datasend("$student_id\n");
> $smtp->datasend("$pf{percent_correct_final}\n");
> $smtp->datasend("squandered: $pf{percent_squandered}\%\n");
> $smtp->datasend("if tried: $pf{if_tried}\%\n");
> $smtp->datasend("string_of_wrongs: $pf{string_of_wrongs}\n");
> foreach (@analysis) {$smtp->datasend("$_\n")};
> $smtp->dataend();
> $smtp->quit;
> return;
> }
>
> SECOND SUBRUTINE:
>
> sub email_mentors {
> my $message   = shift;
> my $to = 'socra...@reason.net'; #was my $to = shift;
> my $from = 'webmas...@libertylearning.com';   
> my $site = 'libertylearning.com';
> my $smtp_host = 'mail.LibertyLearning.com';
>
> my $smtp  = Net::SMTP->new( $smtp_host, Hello => $site );
> $smtp->mail($from);
> $smtp->to($to);
> $smtp->data();
> $smtp->datasend("From: no_reply\@LibertyLearning.com\n");
> $smtp->datasend("To: $to\n");
> $smtp->datasend("Date: $pf{ date_ended }\n");
> $smtp->datasend("Subject: Test Results\n");
> $smtp->datasend("\n");
> $smtp->datasend("$message\n");
> $smtp->dataend();
> $smtp->quit;
>
> return;
> }

-- 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: configuring Net::SMTP

2023-07-08 Thread Claude Brown via beginners
Hi Rick,

We use Net::SMTP to send emails via SendGrid.  They require a user/pass 
authentication over SSL and I wonder if that is what is going wrong in your 
case.  The other thing worth doing is checking the return-value of each SMTP 
call as something may be going wrong silently.

Below is a fragment of our code that does (a) authentication and (b) checks 
each value.  I hope it assists.

Cheers,

Claude.

use strict;
use Carp;
use Net::SMTP;

use constant SMTP_HOST => 'smtp.sendgrid.net';
use constant SMTP_PORT => 465;
use constant SMTP_USER => 'the-username';
use constant SMTP_PASS => 'the-password';
use constant SMTP_TIMEOUT => 15;
use constant SMTP_DEBUG => 0;

my $smtp = Net::SMTP->new(
Host => SMTP_HOST,
Port => SMTP_PORT,
Timeout => SMTP_TIMEOUT,
SSL => 1,
Debug => SMTP_DEBUG);

my $fromAddr = 'whowe...@somehwere.com';
my $toAddr = 'whoe...@somewhere.com';
my $theBody = 'the mail headers and body of the email';

$smtp->auth(SMTP_USER, SMTP_PASS) or confess "SMTP auth: " . $smtp->message();
$smtp->mail($fromAddr)or confess "SMTP mail: " . $smtp->message();
$smtp->to($toAddr)or confess "SMTP to: " . $smtp->message();
$smtp->data() or confess "SMTP data: " . $smtp->message();
$smtp->datasend($theBody) or confess "SMTP datasend: " . 
$smtp->message();
$smtp->dataend()  or confess "SMTP dataend: " . 
$smtp->message();
$smtp->quit() or confess "SMTP quit: " . $smtp->message(); 
--
Claude.


-Original Message-
From: p...@reason.net  
Sent: Sunday, July 9, 2023 10:41 AM
To: Perl Beginners 
Subject: Re: configuring Net::SMTP

CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe.

Thanks, Andinus. This is useful information. — Rick

> On Jul 8, 2023, at 10:11 AM, Andinus  wrote:
>
>
> Hello Rick,
>
> Hostgator might be able to provide you more information regarding why
> the email delivery is failing. I'm not very familiar with mail stuff.
>
> You can also try NET::SMTP->new(Debug => 1) and send an email, it might
> provide useful info.
>
> Maybe this answer on stackoverflow might be helpful
> https://stackoverflow.com/a/10008814
>
> Have a good day!
>
> Rick T @ 2023-07-08 08:37 -07:
>
>> I have two subroutines (below) in a program that uses Net::SMTP. I’ve
>> recently moved my site from FutureQuest.net <http://futurequest.net/>
>> to Hostgator.com <http://hostgator.com/>, and this part of my program
>> has stopped working. The first routine sends an analysis of a test to
>> me at Reason.net <http://reason.net/>, and the second send a score to
>> several addresses associated with the student. On my new host at
>> Hostgator both fail to do this. (One of the “technicians” at Hostgator
>> said he found my email, so one or both likely arrived at
>> webmas...@hostgator.com <mailto:webmas...@hostgator.com>.)
>>
>> I am not trained in computer tech; I’m just a 78 year old high school
>> teacher who bought a few books on perl, so I don’t really understand
>> how to fill in the many variable assignments that make up most of
>> these two routines. Instead I took guesses and tried stuff to see
>> what would happen. If any of you have suggestions or corrections, I’d
>> be grateful!
>>
>> Rick Triplett
>>
>> FIRST SUBROUTINE:
>>
>> sub email_analysis {# to LibertyLearning for score posting and analysis
>>my $n_max = shift;
>>my @analysis = define_analysis($n_max);
>>
>>my $subject_line
>>= "$pf{percent_correct_final} $pf{name_full} $course_file\n";
>>
>># Send administration an email of statistical analysis
>>my $to= 'socra...@reason.net';
>>my $from  = 'webmas...@libertylearning.com';
>>my $site  = 'libertylearning.com';
>>my $smtp_host = 'mail.libertylearning.com';
>>
>>my $smtp  = Net::SMTP->new( $smtp_host, Hello => $site );
>>$smtp->mail($from);
>>$smtp->to($to);
>>$smtp->data();
>>$smtp->datasend("From: webmaster\@LibertyLearning.com\n");
>>$smtp->datasend("To: $to\n");
>>$smtp->datasend("Date: $pf{ date_ended }\n");
>>$smtp->datasend("Subject: $subject_line\n");
>>$smtp->datasend("\n");
>>$smtp->datasend("$student_id\n&q

Re: configuring Net::SMTP

2023-07-08 Thread perl
Thanks, Andinus. This is useful information. — Rick  

> On Jul 8, 2023, at 10:11 AM, Andinus  wrote:
> 
> 
> Hello Rick,
> 
> Hostgator might be able to provide you more information regarding why
> the email delivery is failing. I'm not very familiar with mail stuff.
> 
> You can also try NET::SMTP->new(Debug => 1) and send an email, it might
> provide useful info.
> 
> Maybe this answer on stackoverflow might be helpful
> https://stackoverflow.com/a/10008814
> 
> Have a good day!
> 
> Rick T @ 2023-07-08 08:37 -07:
> 
>> I have two subroutines (below) in a program that uses Net::SMTP. I’ve
>> recently moved my site from FutureQuest.net 
>> to Hostgator.com , and this part of my program
>> has stopped working. The first routine sends an analysis of a test to
>> me at Reason.net , and the second send a score to
>> several addresses associated with the student. On my new host at
>> Hostgator both fail to do this. (One of the “technicians” at Hostgator
>> said he found my email, so one or both likely arrived at
>> webmas...@hostgator.com .)
>> 
>> I am not trained in computer tech; I’m just a 78 year old high school
>> teacher who bought a few books on perl, so I don’t really understand
>> how to fill in the many variable assignments that make up most of
>> these two routines. Instead I took guesses and tried stuff to see
>> what would happen. If any of you have suggestions or corrections, I’d
>> be grateful!
>> 
>> Rick Triplett
>> 
>> FIRST SUBROUTINE:
>> 
>> sub email_analysis {# to LibertyLearning for score posting and analysis
>>my $n_max = shift;
>>my @analysis = define_analysis($n_max);
>> 
>>my $subject_line
>>= "$pf{percent_correct_final} $pf{name_full} $course_file\n";
>> 
>># Send administration an email of statistical analysis
>>my $to= 'socra...@reason.net';
>>my $from  = 'webmas...@libertylearning.com';
>>my $site  = 'libertylearning.com';
>>my $smtp_host = 'mail.libertylearning.com';
>> 
>>my $smtp  = Net::SMTP->new( $smtp_host, Hello => $site );
>>$smtp->mail($from);
>>$smtp->to($to);
>>$smtp->data();
>>$smtp->datasend("From: webmaster\@LibertyLearning.com\n");
>>$smtp->datasend("To: $to\n");
>>$smtp->datasend("Date: $pf{ date_ended }\n");
>>$smtp->datasend("Subject: $subject_line\n");
>>$smtp->datasend("\n");
>>$smtp->datasend("$student_id\n");
>>$smtp->datasend("$pf{percent_correct_final}\n");
>>$smtp->datasend("squandered: $pf{percent_squandered}\%\n");
>>$smtp->datasend("if tried: $pf{if_tried}\%\n");
>>$smtp->datasend("string_of_wrongs: $pf{string_of_wrongs}\n");
>>foreach (@analysis) {$smtp->datasend("$_\n")};
>>$smtp->dataend();
>>$smtp->quit;
>>return;
>> }
>> 
>> SECOND SUBRUTINE:
>> 
>> sub email_mentors {
>>my $message   = shift;
>>my $to= 'socra...@reason.net'; #was my $to = shift;
>>my $from  = 'webmas...@libertylearning.com';
>>my $site  = 'libertylearning.com';
>>my $smtp_host = 'mail.LibertyLearning.com';
>> 
>>my $smtp  = Net::SMTP->new( $smtp_host, Hello => $site );
>>$smtp->mail($from);
>>$smtp->to($to);
>>$smtp->data();
>>$smtp->datasend("From: no_reply\@LibertyLearning.com\n");
>>$smtp->datasend("To: $to\n");
>>$smtp->datasend("Date: $pf{ date_ended }\n");
>>$smtp->datasend("Subject: Test Results\n");
>>$smtp->datasend("\n");
>>$smtp->datasend("$message\n");
>>$smtp->dataend();
>>$smtp->quit;
>> 
>>return;
>> }


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/