Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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 
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: $!"; 

Replies are listed 'Best First'.
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 (Archbishop) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://651830]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2018-03-22 23:45 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (286 votes). Check out past polls.