Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > FAQ 9.20 How do I send mail?

Reply
Thread Tools

FAQ 9.20 How do I send mail?

 
 
PerlFAQ Server
Guest
Posts: n/a
 
      04-05-2011
This is an excerpt from the latest version perlfaq9.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

9.20: How do I send mail?

Use the "sendmail" program directly:

open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From: User Originating Mail <me\@host>
To: Final Destination <you\@otherhost>
Subject: A relevant subject line

Body of the message goes here after the blank line
in as many lines as you like.
EOF
close(SENDMAIL) or warn "sendmail didn't close nicely";

The -oi option prevents "sendmail" from interpreting a line consisting
of a single dot as "end of message". The -t option says to use the
headers to decide who to send the message to, and -odq says to put the
message into the queue. This last option means your message won't be
immediately delivered, so leave it out if you want immediate delivery.

Alternate, less convenient approaches include calling "mail" (sometimes
called "mailx") directly or simply opening up port 25 have having an
intimate conversation between just you and the remote SMTP daemon,
probably "sendmail".

Or you might be able use the CPAN module "Mail::Mailer":

use Mail::Mailer;

$mailer = Mail::Mailer->new();
$mailer->open({ From => $from_address,
To => $to_address,
Subject => $subject,
})
or die "Can't open: $!\n";
print $mailer $body;
$mailer->close();

The "Mail::Internet" module uses "Net::SMTP" which is less Unix-centric
than "Mail::Mailer", but less reliable. Avoid raw SMTP commands. There
are many reasons to use a mail transport agent like "sendmail". These
include queuing, MX records, and security.



--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
 
Reply With Quote
 
 
 
 
Graham Drabble
Guest
Posts: n/a
 
      04-07-2011
On 05 Apr 2011 PerlFAQ Server <> wrote in
newshMmp.31372$:


> 9.20: How do I send mail?
>
> Use the "sendmail" program directly:


<snip>

> Or you might be able use the CPAN module "Mail::Mailer":

<snip>


Is there a reason that this prefers the use of sendmail over the various
CPAN modules that allow use of SMTP directly? As someone who writes a lot
fo Perl for Windows, scritps / modules that use calls to sendmail are a
real pain, those using SMTP directly are much more portable.

--
Graham Drabble
http://www.drabble.me.uk/
 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      04-07-2011
On 2011-04-07 17:49, Graham Drabble <> wrote:
> On 05 Apr 2011 PerlFAQ Server <> wrote in
> newshMmp.31372$:
>> 9.20: How do I send mail?
>>
>> Use the "sendmail" program directly:

>
><snip>
>
>> Or you might be able use the CPAN module "Mail::Mailer":

><snip>
>
>
> Is there a reason that this prefers the use of sendmail over the various
> CPAN modules that allow use of SMTP directly? As someone who writes a lot
> fo Perl for Windows, scritps / modules that use calls to sendmail are a
> real pain, those using SMTP directly are much more portable.


Actually you want to use SUBMISSION (RFC 4409), not SMTP (RFC 5321). But
apart from that I agree that talking a well-defined network protocol is
more portable than and generally preferrable to invoking a program.

(Invoking /usr/sbin/sendmail is a lot simpler, though)

hp

 
Reply With Quote
 
brian d foy
Guest
Posts: n/a
 
      04-08-2011
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]

In article
<>, Graham
Drabble <> wrote:

> On 05 Apr 2011 PerlFAQ Server <> wrote in
> newshMmp.31372$:
>
>
> > 9.20: How do I send mail?
> >
> > Use the "sendmail" program directly:

>
> <snip>
>
> > Or you might be able use the CPAN module "Mail::Mailer":

> <snip>
>
>
> Is there a reason that this prefers the use of sendmail over the various
> CPAN modules that allow use of SMTP directly?


Because no one has rewritten the answer with modern modules. You could
be the one to do that.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ or not FAQ? =?ISO-8859-15?Q?Juli=E1n?= Albo C++ 28 01-15-2007 04:33 AM
FAQ/FAQ notes site makeover Peter Michaux Javascript 22 11-27-2006 01:55 AM
FAQ - How do I direct someone to this FAQ? FAQ server Javascript 1 08-04-2006 10:13 PM
[de] Update of FAQ in German/FAQ auf Deutsch ueberarbeitet Josef 'Jupp' Schugt Ruby 0 09-22-2003 08:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57