Send email: Difference between revisions
m
→{{header|Perl}}: future-proof for 5.36
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: future-proof for 5.36) |
||
Line 1,202:
=={{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.
Line 1,211 ⟶ 1,212:
# Authen::SASL here.
sub send_email {
(from => '', to => [], cc => [],
subject => '', body => '',
Line 1,219 ⟶ 1,220:
ref $o{$_} or $o{$_} = [$o{$_}] foreach 'to', 'cc';
my $smtp =
or die "Couldn't connect to SMTP server";
Line 1,236 ⟶ 1,237:
$smtp->dataend;
return 1;
}</syntaxhighlight>
An example call:
Line 1,256 ⟶ 1,258:
user => 'tappman@example.com';</syntaxhighlight>
===Using 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->post()</code> method does not suit since it constructs a message as MIME "form data".
|