Send email: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (→‎{{header|Perl}}: future-proof for 5.36)
Line 1,202: Line 1,202:


=={{header|Perl}}==
=={{header|Perl}}==
===Using Net::SMTP===
This subroutine throws an appropriate error if it fails to connect to the server or authenticate. It should work on any platform Perl does.
This subroutine throws an appropriate error if it fails to connect to the server or authenticate. It should work on any platform Perl does.


Line 1,211: Line 1,212:
# Authen::SASL here.
# Authen::SASL here.


sub send_email
sub send_email {
{my %o =
my %o =
(from => '', to => [], cc => [],
(from => '', to => [], cc => [],
subject => '', body => '',
subject => '', body => '',
Line 1,219: Line 1,220:
ref $o{$_} or $o{$_} = [$o{$_}] foreach 'to', 'cc';
ref $o{$_} or $o{$_} = [$o{$_}] foreach 'to', 'cc';


my $smtp = new Net::SMTP($o{host} ? $o{host} : ())
my $smtp = Net::SMTP->new($o{host} ? $o{host} : ())
or die "Couldn't connect to SMTP server";
or die "Couldn't connect to SMTP server";


Line 1,236: Line 1,237:
$smtp->dataend;
$smtp->dataend;


return 1;}</syntaxhighlight>
return 1;
}</syntaxhighlight>


An example call:
An example call:
Line 1,256: Line 1,258:
user => 'tappman@example.com';</syntaxhighlight>
user => 'tappman@example.com';</syntaxhighlight>


===Using LWP===
{{libheader|LWP}}

LWP can send email by a POST to a <code>mailto:</code> URL. The message is given as a HTTP request. This is mainly of interest for treating different types of URLs in a common way. LWP sends merely by running the <code>sendmail</code> program, or on MacOS classic by SMTP (to <code>SMTPHOSTS</code> environment variable). For reference, the <code>$ua-&gt;post()</code> method does not suit since it constructs a message as MIME "form data".
LWP can send email by a POST to a <code>mailto:</code> URL. The message is given as a HTTP request. This is mainly of interest for treating different types of URLs in a common way. LWP sends merely by running the <code>sendmail</code> program, or on MacOS classic by SMTP (to <code>SMTPHOSTS</code> environment variable). For reference, the <code>$ua-&gt;post()</code> method does not suit since it constructs a message as MIME "form data".