Re: Where is "Subject"?

2017-02-27 Thread ToddAndMargo

On 02/27/2017 11:34 PM, ToddAndMargo wrote:

Hi All,

Follow up on Net::SMTP:

Thank you for all the help!

I am posting this back to help others.  And, yes, I know I
don't have to use "~" so much.

-T

Comments:

1) "@to" is an array, not a string

2) the "To:", "From:", and "Subject:" are headers that
   you make up yourself.  And they are comments that
   show up on the receiver.  They are not the actual
   "To:", "From:", and "Subject:"

3) you terminate the headers with a blank line and
   add them to you message.

4) :diag turns on all output of the transaction.  Errors
   are output to STDERR ($ERR) regardless of the state
   of :diag

Here is a copy of a sub I wrote to handle this:


sub eMailReport () {
   # Reference: https://github.com/retupmoca/P6-Net-SMTP
   my $smtp = "a";
   my $port = ;
   my $username = "ccc";
   my $password = "ddd";


Ooops: forgot this:

   my $from = "$username";


   my @to   = qw [ xxx yyys ];   # This is an array, not a string

   # Note: prepend headers followed by a blank line to the message
   my $Headers;
   for @to { $Headers ~= "To: " ~ "$_" ~ "\n"; }
   $Headers ~= "From: " ~ "$IAm " ~ "<" ~ "$username" ~ ">\n";
   $Headers ~= "Subject: $IAm ERROR(s) = $ErrorCount\n\n";

   my $Message  = "$Headers" ~ "$Report";

   # Note: :debug will send all output to stderr.  (Errors will always
be sent regardless.)
   # if ( not my $client = Net::SMTP.new(:server( $smtp ), :port( $port
), :debug ) ) {
   if ( not my $client = Net::SMTP.new(:server( $smtp ), :port( $port )
) ) {
   $ErrorCount += 1;
   PrintRed( "SMTP: unable to open $smtp\n" );
   AddToReport ( "SMTP: unable to open $smtp\n" );
   return;
}

   if ( not $client.auth( $username, $password ) ) {
   $ErrorCount += 1;
   PrintRed( "SMTP: something is wrong with the username and/or
password\n\n" );
   AddToReport ( "SMTP: something is wrong with the username and/or
password\n\n" );
   return;
}

   if ( not $client.send( $from, @to, $Message ) ) { PrintRed "SMTP
Error: Failed to send\n\n"; }

   $client.quit;
}




--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Where is "Subject"?

2017-02-27 Thread ToddAndMargo

Hi All,

Follow up on Net::SMTP:

Thank you for all the help!

I am posting this back to help others.  And, yes, I know I
don't have to use "~" so much.

-T

Comments:

1) "@to" is an array, not a string

2) the "To:", "From:", and "Subject:" are headers that
   you make up yourself.  And they are comments that
   show up on the receiver.  They are not the actual
   "To:", "From:", and "Subject:"

3) you terminate the headers with a blank line and
   add them to you message.

4) :diag turns on all output of the transaction.  Errors
   are output to STDERR ($ERR) regardless of the state
   of :diag

Here is a copy of a sub I wrote to handle this:


sub eMailReport () {
   # Reference: https://github.com/retupmoca/P6-Net-SMTP
   my $smtp = "a";
   my $port = ;
   my $username = "ccc";
   my $password = "ddd";
   my @to   = qw [ xxx yyys ];   # This is an array, not a string

   # Note: prepend headers followed by a blank line to the message
   my $Headers;
   for @to { $Headers ~= "To: " ~ "$_" ~ "\n"; }
   $Headers ~= "From: " ~ "$IAm " ~ "<" ~ "$username" ~ ">\n";
   $Headers ~= "Subject: $IAm ERROR(s) = $ErrorCount\n\n";

   my $Message  = "$Headers" ~ "$Report";

   # Note: :debug will send all output to stderr.  (Errors will always 
be sent regardless.)
   # if ( not my $client = Net::SMTP.new(:server( $smtp ), :port( $port 
), :debug ) ) {
   if ( not my $client = Net::SMTP.new(:server( $smtp ), :port( $port ) 
) ) {

   $ErrorCount += 1;
   PrintRed( "SMTP: unable to open $smtp\n" );
   AddToReport ( "SMTP: unable to open $smtp\n" );
   return;
}

   if ( not $client.auth( $username, $password ) ) {
   $ErrorCount += 1;
	   PrintRed( "SMTP: something is wrong with the username and/or 
password\n\n" );
	   AddToReport ( "SMTP: something is wrong with the username and/or 
password\n\n" );

   return;
}

   if ( not $client.send( $from, @to, $Message ) ) { PrintRed "SMTP 
Error: Failed to send\n\n"; }


   $client.quit;
}



Re: Where is "Subject"?

2017-02-24 Thread ToddAndMargo

On 02/24/2017 04:05 AM, Luca Ferrari wrote:

"$Subject$StringFullOfLineFeeds);


Guilty as charged.  I missed the quote at the end of the line.


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Where is "Subject"?

2017-02-24 Thread Brandon Allbery
On Fri, Feb 24, 2017 at 2:50 AM, Luca Ferrari  wrote:

> On Fri, Feb 24, 2017 at 7:51 AM, ToddAndMargo 
> wrote:
> > Am I blind or is there nowhere to set the subject of an eMail
> > in Net::SMTP?
>
> I suspect it is implementing a quite low-level interface: smtp does
> not know anything about a subject, it simply sends it as a line
> "Subject: foo bar"
> followed by an empty line a your message body. In other words: the
> subject is in the payload before your message content.
>

Same thing as when you asked about attaching files; I think I mentioned at
the time it also didn't include headers. Subject: is probably the most
important header --- although many mail systems will reject it if it also
doesn't have From: and preferably Date: and Message-Id:.

You might poke around to see if there is a module that implements at least
RFC822 and preferably RFC2422 to build a proper message.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Where is "Subject"?

2017-02-24 Thread Luca Ferrari
Seems to me it has to work, but I would suggest a couple of little
changes to make the source code more readable (see below):

On Fri, Feb 24, 2017 at 9:15 AM, ToddAndMargo  wrote:
>for @Report -> $Line { $StringFullOfLineFeeds .= ( "$Line" ~ "\n" ); }

here I would use join, much simpler than a for-string-concatenation

> "$Subject$StringFullOfLineFeeds);

here I would use explicit string concatenation to make it clearer you
are using two variables on the same line. Don't you miss a double
tick?

Luca


Re: Where is "Subject"?

2017-02-24 Thread ToddAndMargo

On 02/23/2017 11:50 PM, Luca Ferrari wrote:

On Fri, Feb 24, 2017 at 7:51 AM, ToddAndMargo  wrote:

Hi All,

Am I blind or is there nowhere to set the subject of an eMail
in Net::SMTP?


I suspect it is implementing a quite low-level interface: smtp does
not know anything about a subject, it simply sends it as a line
"Subject: foo bar"
followed by an empty line a your message body. In other words: the
subject is in the payload before your message content.

Luca




Hi Luca,

Thank you!

-T

This is what I will try if I can ever get
Net::SMTP to install:


sub eMailReport ( $message ) {
   # Reference: https://github.com/retupmoca/P6-Net-SMTP

   my $Subject = "Subject: $IAm ERROR(s) = $ErrorCount\n\n";

   if $ErrorCount eq 0 { AddToReport ( "Completed without errors\n" ); }
   else { AddToReport ( "Completed with $ErrorCount errors\n" ); }

   my $StringFullOfLineFeeds;
   for @Report -> $Line { $StringFullOfLineFeeds .= ( "$Line" ~ "\n" ); }

   my $client = Net::SMTP.new(:server("smtpout.secureserver.net"), 
:port(3535), :debug);

   $client.auth( "p...@storall.biz", "admin");
   $client.send("p...@storall.biz", "p...@storall.biz,tmew...@zoho.com",
"$Subject$StringFullOfLineFeeds);
   $client.quit;
}



--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Where is "Subject"?

2017-02-23 Thread Luca Ferrari
On Fri, Feb 24, 2017 at 7:51 AM, ToddAndMargo  wrote:
> Hi All,
>
> Am I blind or is there nowhere to set the subject of an eMail
> in Net::SMTP?

I suspect it is implementing a quite low-level interface: smtp does
not know anything about a subject, it simply sends it as a line
"Subject: foo bar"
followed by an empty line a your message body. In other words: the
subject is in the payload before your message content.

Luca


Re: Where is "Subject"?

2017-02-23 Thread Moritz Lenz
Hi,

On 24.02.2017 07:51, ToddAndMargo wrote:
> Am I blind or is there nowhere to set the subject of an eMail
> in Net::SMTP?
> 
> https://github.com/retupmoca/P6-Net-SMTP

You're not blind, just thinking at the wrong level. Net::SMTP expects
you to have an email string that contains both the headers and the body
($email in the README), and the subject is part of the headers.

The only reason that $from and @to have a separate interface is that
SMTP handles them separately.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/