Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using Email::Sender to send a link

440 views
Skip to first unread message

Cal Dershowitz

unread,
Jun 12, 2016, 10:19:30 PM6/12/16
to
Hello newsgroup,

I'm glad to have a hobby that doesn't involve the tv today but wouldn't
want to start an exposition without noticing the loss in Orlando....

I've been trying to email using perl on a windows 8.1 machine. It's a
curious platypus of a platform with cygwin to give me perl, and windows
to give me an OS that gives me internet and a printer but is opaque to a
person who is trying to figure it out using dos. I typed ipconfig and
didn't see anything relevant.

Also been reading about how to send email with perl, including an
article that says there are 937 ways to send email with perl, so peeved
that my sixth pretty good try does not attain.

Current script and output:

C:\cygwin64\home\Fred\pages2\plot\alpaca>perl alpaca6.pl

page is ydp7k1.html
host is smtp.1and1.com
Can't locate object method "new" via package
"Email::Sender::Transport::SMTP" at
alpaca6.pl line 38.

C:\cygwin64\home\Fred\pages2\plot\alpaca>type alpaca6.pl
use strict;
use 5.010;
use lib "template_stuff";
use html3;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;

sub rndStr {
join '', @_[ map { rand @_ } 1 .. shift ];
}
my $new_name = rndStr( 5, 'a' .. 'z', 1 .. 9 );
my $ref_to_name = \$new_name;
my $return_page = create_page($ref_to_name);
say "page is $return_page";
email_link($return_page);

sub email_link {
use strict;
use 5.014;
use Net::SMTP;
use config2;

my $link = shift;
my $sub_hash = "my_ftp";
my $host = $config{$sub_hash}->{'smtp'};
say "host is $host";
my $phone = $config{$sub_hash}->{'phone'};

#say "phone is $phone";
my $username = $config{$sub_hash}->{'username'};

#say "username is $username";
my $password = $config{$sub_hash}->{'password'};

#say "password is $password";

my $transport = Email::Sender::Transport::SMTP->new(
{
host => $host,
port => 587,
}
);

my $email = Email::Simple->create(
header => [
To => '"Xavier Q. Ample" <$phone>',
From => '"Bob Fishman" <o...@example.mil>',
Subject => "don't forget to *enjoy the sauce*",
],
body => "This message is short, but at least it's cheap.\n",
);
sendmail( $email, { transport => $transport } );

}

#end script

The ftp values I have from my html library work for everything else I
use it for. cpan thinks that Email::Sender::Transport::SMTP is up to
date. I'm able to send email to this phone using gmail, but that's the
precise step that I want to cut out of this operation. I called my ISP
and learned that smtp should be TLS-enabled. Thank you for your comment.
--
Cal



George Mpouras

unread,
Jun 13, 2016, 12:43:21 PM6/13/16
to
On 13/6/2016 05:19, Cal Dershowitz wrote:


> curious platypus of a platform with cygwin to give me perl


If you are only interesting using Perl at your windows and not meshing
up with other linux technolies, I strongly recomment to uninstall Cygwin
and install strawberry Perl from here
http://strawberryperl.com/download/5.24.0.1/strawberry-perl-5.24.0.1-64bit.msi


C.DeRykus

unread,
Jun 14, 2016, 12:15:49 AM6/14/16
to

Cal Dershowitz

unread,
Jun 15, 2016, 12:03:30 AM6/15/16
to
Well, george, your suggestion opened up a can of worms. I found out
that I had unused activestate and strawberry perl installs. I'm coming
around to the position that I have to hack out what's here because it
looks awful, but I might need to have a direction to go with it.

I'm trying to develop in the idiom of _Intermediate Perl_, where the
castaways are putting their useful code into modules. My html routines
won't be portable unless they have a path to all the modules they
require that don't come with the distribution itself.

Can I achieve this by setting the local::lib and then putting everything
in it my templates need to run?
--
Cal

Cal Dershowitz

unread,
Jun 15, 2016, 2:43:08 PM6/15/16
to
On 6/13/2016 9:15 PM, C.DeRykus wrote:

> I have no experience with the module but this may be worth
> a look:
>
> http://search.cpan.org/~fayland/Email-Sender-Transport-SMTP-TLS-0.15/lib/Email/Sender/Transport/SMTP/TLS.pm
>

Thanks for your suggestion, C., I took the example code, filled in my
values and got this:

C:\Users\Fred\Documents\alpaca>perl alpaca7.pl
Can't locate Email/Sender/Transport/SMTP/TLS.pm in @INC (@INC contains:
template
_stuff C:/Perl/site/lib C:/Perl/lib .) at alpaca7.pl line 36.
BEGIN failed--compilation aborted at alpaca7.pl line 36.

Truly and verily, TLS.pm was not there, which led to another round of
investigation. Rather than describe what I found, for brevity's sake,
let me say that I removed activestate, strawberry perl, and cygwin,
leaving me here:

C:\Users\Fred\Desktop>perl anything
'perl' is not recognized as an internal or external command,
operable program or batch file.

I'm gonna do some clean-up--suggestions here taken gladly--and then
install strawberry perl as george suggested.

I think the best way forward for my little project will then be this,
which is suggested as a better way to go from your above link:

http://search.cpan.org/~fayland/Email-Sender-Transport-SMTPS-0.03/lib/Email/Sender/Transport/SMTPS.pm#send_email_with_Gmail
--
Cal


Rainer Weikusat

unread,
Jun 15, 2016, 3:00:48 PM6/15/16
to
Cal Dershowitz <C...@example.invalid> writes:

[...]

> Current script and output:
>
> C:\cygwin64\home\Fred\pages2\plot\alpaca>perl alpaca6.pl
>
> page is ydp7k1.html
> host is smtp.1and1.com
> Can't locate object method "new" via package
> "Email::Sender::Transport::SMTP" at
> alpaca6.pl line 38.
>
> C:\cygwin64\home\Fred\pages2\plot\alpaca>type alpaca6.pl
> use strict;
> use 5.010;
> use lib "template_stuff";
> use html3;
> use Email::Sender::Simple qw(sendmail);
> use Email::Simple;
> use Email::Simple::Creator;

[...]
Email::Sender::Simple loads Email::Sender::Transport::SMTP dynamically
via require in case it wants to use it. This and the error above suggest
that you need a

use Email::Sender::Transport::SMTP;

before you can call methods of it.

C.DeRykus

unread,
Jun 15, 2016, 3:38:07 PM6/15/16
to
On Wednesday, June 15, 2016 at 11:43:08 AM UTC-7, Cal Dershowitz wrote:
> On 6/13/2016 9:15 PM, C.DeRykus wrote:
>
> > I have no experience with the module but this may be worth
> > a look:
> >
> > http://search.cpan.org/~fayland/Email-Sender-Transport-SMTP-TLS-0.15/lib/Email/Sender/Transport/SMTP/TLS.pm
> >
>
> Thanks for your suggestion, C., I took the example code, filled in my
> values and got this:
>
> C:\Users\Fred\Documents\alpaca>perl alpaca7.pl
> Can't locate Email/Sender/Transport/SMTP/TLS.pm in @INC (@INC contains:
> template
> _stuff C:/Perl/site/lib C:/Perl/lib .) at alpaca7.pl line 36.
> BEGIN failed--compilation aborted at alpaca7.pl line 36.
>
> Truly and verily, TLS.pm was not there, which led to another round of
> investigation. Rather than describe what I found, for brevity's sake,
> let me say that I removed activestate, strawberry perl, and cygwin,
> leaving me here:
>
> C:\Users\Fred\Desktop>perl anything
> 'perl' is not recognized as an internal or external command,
> operable program or batch file.
>
> I'm gonna do some clean-up--suggestions here taken gladly--and then
> install strawberry perl as george suggested.
>
> I think the best way forward for my little project will then be this,
> which is suggested as a better way to go from your above link:
>

FWIW a test program worked:

use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::TLS;
use Email::Simple::Creator; # or other Email::
use Try::Tiny;

my $transport = Email::Sender::Transport::SMTP::TLS->new(
host => 'smtp.gmail.com',
port => 587,
username => '--------@gmail.com',
password => '----------',
helo => 'derykus',
);


my $message = Email::Simple->create(
header => [
From => '---------@gmail.com',
To => 'other--...@gmail.com',
Subject => 'A test case using smtp::tls',
],
body => 'will this work using gmail?',
);

try {
sendmail($message, { transport => $transport });
} catch {
die "Error sending email: $_";
};






John Black

unread,
Jun 15, 2016, 5:17:45 PM6/15/16
to
In article <bedab494-02f3-4eef...@googlegroups.com>,
der...@gmail.com says...
> my $transport = Email::Sender::Transport::SMTP::TLS->new(
> host => 'smtp.gmail.com',
> port => 587,
> username => '--------@gmail.com',
> password => '----------',
> helo => 'derykus',
> );
>

Stupid question, but we're allowed to use gmail's smtp to send mail??

John Black

$Bill

unread,
Jun 15, 2016, 8:09:22 PM6/15/16
to
All of my TBird mail goes out through the default gmail server, but I use
the smtp.googlemail.com addy to send.

Cal Dershowitz

unread,
Jun 15, 2016, 11:32:53 PM6/15/16
to
Hope so. :) You look at the authentication, and it's no different than
making the keystrokes yourself for your own account. You are *not*
allowed to use mine, but the guys at google don't seem to be stingy in
giving away accounts for the price of the asking.

Victory has attained. I have managed to conquer one of the rumored 937
ways to send email in perl:

page is rz5251.html
host is smtp.gmail.com
phone is ...@txt.att.net
username is ...@gmail.com
password is ...

C:\Users\Fred\Documents\alpaca>perltidy -i=3 -b alpaca8.pl

C:\Users\Fred\Documents\alpaca>type alpaca8.pl
use strict;
use 5.014;
use lib "template_stuff";
use html3;

sub rndStr {
join '', @_[ map { rand @_ } 1 .. shift ];
}
my $new_name = rndStr( 5, 'a' .. 'z', 1 .. 9 );
my $ref_to_name = \$new_name;
my $return_page = create_page($ref_to_name);
say "page is $return_page";
my $munge_http = "http://merrillpjensen.com/maps/$return_page";
email_link($munge_http);

sub email_link {
use strict;
use 5.014;
use config3;

my $link = shift;
my $sub_hash = "gmail";
my $host = $config{$sub_hash}->{'host'};
say "host is $host";
my $phone = $config{$sub_hash}->{'phone'};

say "phone is $phone";
my $username = $config{$sub_hash}->{'sasl_username'};

say "username is $username";
my $password = $config{$sub_hash}->{'sasl_password'};

say "password is $password";

use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTPS;
use Try::Tiny;

my $transport = Email::Sender::Transport::SMTPS->new(
host => $host,
ssl => 'starttls',
sasl_username => $username,
sasl_password => $password,
debug => 0, # or 1
);

use Email::Simple::Creator; # or other Email::
my $message = Email::Simple->create(
header => [
From => $username,
To => $phone,
Subject => 'Subject title',
],
body => "Your link is $link\n",
);

try {
sendmail( $message, { transport => $transport } );
}
catch {
die "Error sending email: $_";
};

}

In addition to tearing out and re-installing my own windows-based perl
implementation, I created a new gmail account as well as a new way to
represent it in my configuration files. Ben Bacarisse may recognize this
config file, as the "my_ftp" part of it follows how he recommended I
remove sensitive values from the rest of my ftp-heavy template.

In this case, I create I subhash called 'gmail' to do the necessary work:

C:\Users\Fred\Documents\alpaca>cd template_stuff

C:\Users\Fred\Documents\alpaca\template_stuff>type config3.pm
package config3;
use Exporter qw(import);
our @EXPORT = qw(%config);
our %config = (
my_ftp => {
domain => irrelevant,
username => irrelevant,
password => irrelevant,
smtp => irrelevant,
phone => irrelevant,
site => irrelevant,
},

gmail => {

phone => '...@txt.att.net',
host => 'smtp.gmail.com',
ssl => 'starttls',
sasl_username => '...',
sasl_password => '...',

},
);
1;

I believe that the critical value that has been missing on previous
efforts is this one:
ssl => 'starttls',

There really is an alpaca farm here:

http://merrillpjensen.com/maps/rltrb1.html

Thanks all for comments on my html template quest.
--
Cal

Cal Dershowitz

unread,
Jun 15, 2016, 11:45:25 PM6/15/16
to
Does it have authentication?
--
Cal

$Bill

unread,
Jun 15, 2016, 11:57:08 PM6/15/16
to
It's options are currently set to:

Port 465; SSL/TLS (vs none/STARTTLS); username;
normal password (vs no auth, enc passwd, Kerberos/GSSAPI, NTLM, OAuth2);

As you can see, there are several choices avail for TBird default outgoing server.

George Mpouras

unread,
Jun 17, 2016, 8:35:35 AM6/17/16
to
>
> I'm trying to develop in the idiom of _Intermediate Perl_, where the
> castaways are putting their useful code into modules. My html routines
> won't be portable unless they have a path to all the modules they
> require that don't come with the distribution itself.
>
> Can I achieve this by setting the local::lib and then putting everything
> in it my templates need to run?


Your code can load your modules no matter where your main script is with
this old trick

use FindBin;
use lib $FindBin::Bin;

or
"$FindBin::Bin/my modules"
or
use lib "$FindBin::Bin/../clever dude";

Do not put the code inside tbe templates . Your main script feed the
templates with data at their placeholders. Check the template toolkit

From the templates you call main script subroutines
You can also put arbitary code inside the template but I do not recomended.


You can also write your template plugins

Cal Dershowitz

unread,
Jun 19, 2016, 4:23:16 AM6/19/16
to
On 6/17/2016 5:36 AM, George Mpouras wrote:

> Your code can load your modules no matter where your main script is with
> this old trick
>
> use FindBin;
> use lib $FindBin::Bin;
>
> or
> "$FindBin::Bin/my modules"
> or
> use lib "$FindBin::Bin/../clever dude";
>
> Do not put the code inside tbe templates . Your main script feed the
> templates with data at their placeholders. Check the template toolkit
>
> From the templates you call main script subroutines
> You can also put arbitrary code inside the template but I do not recommended.
>
>
> You can also write your template plugins

ok, I'm looking at this material on p. 20 of _Intermediate Perl_. What's
more, I installed a local::lib with the default value from the
strawberry perl tool claiming to do precisely this, and what I see are
paths that look equal parts exotic and errant to my eye, explaining why
I can't find anything like a local::lib :


C:\Users\Fred\Documents\math>perl -Mlocal::lib
@if not "%PATH%"=="" set "PATH=C:\Users\Fred/perl5\bin;%PATH%"
@if "%PATH%"=="" @set "PATH=C:\Users\Fred/perl5\bin"
@if not "%PERL5LIB%"=="" set
"PERL5LIB=C:\Users\Fred/perl5\lib\perl5;%PERL5LIB%"

@if "%PERL5LIB%"=="" @set "PERL5LIB=C:\Users\Fred/perl5\lib\perl5"
@if not "%PERL_LOCAL_LIB_ROOT%"=="" set
"PERL_LOCAL_LIB_ROOT=C:\Users\Fred/perl5
;%PERL_LOCAL_LIB_ROOT%"
@if "%PERL_LOCAL_LIB_ROOT%"=="" @set
"PERL_LOCAL_LIB_ROOT=C:\Users\Fred/perl5"
@set "PERL_MB_OPT=--install_base "C:\\Users\\Fred/perl5""
@set "PERL_MM_OPT=INSTALL_BASE=C:\\Users\\Fred/perl5"

C:\Users\Fred\Documents\math>

Is this all garbage?
--
Cal
0 new messages