Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Send email using perl and sendmail

by sKore
on Nov 20, 2007 at 01:23 UTC ( #651830=sourcecode: print w/ replies, xml ) Need Help??

Category: E-Mail Programs
Author/Contact Info sKore
Description: Send email using perl and sendmail
#!/usr/bin/env perl 
# postman.pl 
use warnings; 
use strict; 
use Data::Dumper; 

my $sendmail = "/usr/sbin/sendmail -t"; 
my $reply_to = "Reply-to: <mymaild>\@<mymailbox>.com\n"; 
my $subject = "Subject: <subjectline>\n"; 
my $content = "Welcome to ooty, nice to meet you\n"; ## not used actua
+lly read from file instead of this 
my $from = "From: "."<mymaild>\@<mymailbox>.com\n"; 
my $to = "To: "."<yourmaild&>\@<yourmailboxgt\n"; 

my $regfolder=`date +%m%d%Y`; 
my $dateString=`date +%m.%d.%Y`; 

##### Change directory to the folder of file 
my $cmdString = "/home/logfiles/$regfolder"; 
chdir($cmdString)|| die "Error: could not '$cmdString'"; 
##### Mailing the contents 
my $file = "Myspace$dateString.html"; 
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!"; 
print SENDMAIL $reply_to; 
print SENDMAIL $subject; 
print SENDMAIL $from; 
print SENDMAIL $to; 
print SENDMAIL "Content-type: text/html\n\n"; 
open(FILE, "$file") or die "Cannot open $file: $!"; 
print SENDMAIL <FILE> 
close(FILE); 
close(SENDMAIL);


Comment on Send email using perl and sendmail
Download Code
Re: Send email using perl and sendmail
by grinder (Bishop) on Nov 20, 2007 at 12:46 UTC

    No-one seriously sends e-mail these days using the sendmail binary. This approach has been obsolete for more than a decade. There are many good pure-Perl solutions that are much more flexible.

    Have a look at Mail::Sendmail (which does not use sendmail), MIME::Entity, Net::SMTP and Mail::Mailer for a start.

    • another intruder with the mooring in the heart of the Perl

Re: Send email using perl and sendmail
by ww (Bishop) on Nov 20, 2007 at 13:12 UTC
    As in Create HTML files using perl on the fly (posted a mere five minutes earlier), your code does NOT compile (for example, line 29 lacks a semi, separator).

    Since you're a new monk, may I suggest that you will get closer review (and you may get better help) if you demonstrate more care in removing easy-to-find errors like that before posting...
    and if you are posting seeking comments, please post as SOPW; not as something an unwary noob may think is good code.

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://651830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2014-12-26 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls