Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Send-email/Perl/send-email-1.pl
Normal file
34
Task/Send-email/Perl/send-email-1.pl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use Net::SMTP;
|
||||
use Authen::SASL;
|
||||
# Net::SMTP's 'auth' method needs Authen::SASL to work, but
|
||||
# this is undocumented, and if you don't have the latter, the
|
||||
# method will just silently fail. Hence we explicitly use
|
||||
# Authen::SASL here.
|
||||
|
||||
sub send_email {
|
||||
my %o =
|
||||
(from => '', to => [], cc => [],
|
||||
subject => '', body => '',
|
||||
host => '', user => '', password => '',
|
||||
@_);
|
||||
ref $o{$_} or $o{$_} = [$o{$_}] foreach 'to', 'cc';
|
||||
|
||||
my $smtp = Net::SMTP->new($o{host} ? $o{host} : ())
|
||||
or die "Couldn't connect to SMTP server";
|
||||
|
||||
$o{password} and
|
||||
$smtp->auth($o{user}, $o{password}) ||
|
||||
die 'SMTP authentication failed';
|
||||
|
||||
$smtp->mail($o{user});
|
||||
$smtp->recipient($_) foreach @{$o{to}}, @{$o{cc}};
|
||||
$smtp->data;
|
||||
$o{from} and $smtp->datasend("From: $o{from}\n");
|
||||
$smtp->datasend('To: ' . join(', ', @{$o{to}}) . "\n");
|
||||
@{$o{cc}} and $smtp->datasend('Cc: ' . join(', ', @{$o{cc}}) . "\n");
|
||||
$o{subject} and $smtp->datasend("Subject: $o{subject}\n");
|
||||
$smtp->datasend("\n$o{body}");
|
||||
$smtp->dataend;
|
||||
|
||||
return 1;
|
||||
}
|
||||
9
Task/Send-email/Perl/send-email-2.pl
Normal file
9
Task/Send-email/Perl/send-email-2.pl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
send_email
|
||||
from => 'A. T. Tappman',
|
||||
to => ['suchandsuch@example.com', 'soandso@example.org'],
|
||||
cc => 'somebodyelse@example.net',
|
||||
subject => 'Important message',
|
||||
body => 'I yearn for you tragically.',
|
||||
host => 'smtp.example.com:587',
|
||||
user => 'tappman@example.com',
|
||||
password => 'yossarian';
|
||||
3
Task/Send-email/Perl/send-email-3.pl
Normal file
3
Task/Send-email/Perl/send-email-3.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
send_email
|
||||
to => 'suchandsuch@example.com',
|
||||
user => 'tappman@example.com';
|
||||
22
Task/Send-email/Perl/send-email-4.pl
Normal file
22
Task/Send-email/Perl/send-email-4.pl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use strict;
|
||||
use LWP::UserAgent;
|
||||
use HTTP::Request;
|
||||
|
||||
sub send_email {
|
||||
my ($from, $to, $cc, $subject, $text) = @_;
|
||||
|
||||
my $ua = LWP::UserAgent->new;
|
||||
my $req = HTTP::Request->new (POST => "mailto:$to",
|
||||
[ From => $from,
|
||||
Cc => $cc,
|
||||
Subject => $subject ],
|
||||
$text);
|
||||
my $resp = $ua->request($req);
|
||||
if (! $resp->is_success) {
|
||||
print $resp->status_line,"\n";
|
||||
}
|
||||
}
|
||||
|
||||
send_email('from-me@example.com', 'to-foo@example.com', '',
|
||||
"very important subject",
|
||||
"Body text\n");
|
||||
Loading…
Add table
Add a link
Reference in a new issue