go to a link, save the page and email it out?

C

Christopher Nehren

Does anyone know if there is a perl module to do the above?
Thanks. -Dale

package MailPage;
use strict;
use warnings FATAL => 'all';

use LWP::Simple;
use MIME::Lite;
use Carp;
use base qw/Exporter/;
use vars qw/@EXPORT_OK/;
@EXPORT_OK = qw/mail_page/;

sub mail_page
{
croak "mail_page needs four arguments!" unless @_ == 4;
my ($page, $from, $to, $subject) = @_;
my $content = get($page);
croak "Couldn't fetch $page!" unless defined $content;
my $msg = MIME::Lite->new
(
From => $from,
To => $to,
Subject => $subject,
Data => $content,
);
$msg->send() or carp "Uh oh, problems sending mail!"
}
1;
__END__

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';

use MailPage qw/mail_page/;
mail_page(q#http://www.google.com#, q#[email protected]#,
q#[email protected]#, q#A Test#);

__END__

WFM. Took about 5 minutes (mostly because I'm not too familiar with most
of the modules used).

/me braces for the inevitable torrent of code review he's going to
receive...

Best Regards,
Christopher Nehren
 
C

Christopher Nehren

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

$msg->send() or carp "Uh oh, problems sending mail!"
^^^^

Self-review: that should probably be croak.

Best Regards,
Christopher Nehren
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQFBvy8+k/lo7zvzJioRAq4RAKCZDdQsKGN3Qwt526VnfKUfaXss+QCgluo4
Uzpdd3l6dWZ7lutd+tTY288=
=JDeH
-----END PGP SIGNATURE-----
 
D

dale

HTML::Mail works for some web sites. But some web sites have
protections for reading some files, which is expected. THe results are:

C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.

C:\Perl\scripts>

However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?

Thanks a lot. -Dale
 
D

dale

HTML::Mail works for some web sites. But some web sites have
protections for reading some files, which is expected. THe results are:

C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.

C:\Perl\scripts>

However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?

Thanks a lot. -Dale
 
D

dale

Tried the simple one.

HTML::Mail works for some web sites. But some web sites have
protections for reading some files, which is expected. THe results are:

C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.

C:\Perl\scripts>

However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?

Thanks a lot. -Dale
 
D

dalewz

HTML::Mail works for some web sites. But some web sites have
protections for reading some files, which is expected. THe results are:

C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.

C:\Perl\scripts>

-----Mail.pm
164 my $response = $self->{'_ua'}->get($uri);
165
166 if (!$response->is_success) {
167 die "Error while making request [ GET ", $response->request->uri,
"]\n", $response->status_line;
168 }

However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?

Thanks a lot. -Dale
 
M

Matija Papec

X-Ftn-To: dale

dale said:
HTML::Mail works for some web sites. But some web sites have
protections for reading some files, which is expected. THe results are:

I'm not sure if protection is the case but you can convince other side that
you're using fancy browser,
$html_mail->lwp_ua->agent("Mozilla/5.0");
C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.

C:\Perl\scripts>

However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?

Probably there is no image and IE doesn't bother about that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top