Sending Mail

You can get Perl to send email in several ways. One method that you see frequently is opening a pipe to the sendmail command and sending data to it (shown in Listing 41.5). Another method is using the Mail::Sendmail module (available through CPAN), which uses socket connections directly to send mail (as shown in Listing 41.6). The latter method is faster because it does not have to launch an external process. Note that sendmail must be running on your system for the Perl program in Listing 41.5 to work.

LISTING 41.5 Sending Mail Using Sendmail

#!/usr/bin/perlopen (MAIL, "| /usr/sbin/sendmail -t"); # Use -t to protect from usersprint MAIL <<EndMail;To: you\From: me\Subject: A Sample Email\nSending email ...

Get Ubuntu Unleashed 2015 Edition: Covering 14.10 and 15.04, Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.