Hi Monks,
You can pretty much call me a Perl noob but I've had a go at least so please be gentle.
I’ve had a request to create a script to do a mass email to our clients (3k+) with data in individual files. The client email address will be in the first line of the file, subject in the second line and individual data in the rest of the file. Data format is csv and files will have a .csv extention. What I’ve written so far is:
#!/usr/bin/perl -w $dir="/home/jwood/files"; opendir (JDE,$dir) or die "Cannot open $dir: $!"; while ( defined ($file = readdir JDE) ) { next if $file =~ /^\.\.?$/; my $filename = "$dir/$file"; print "$filename\n"; open CFILE, "$filename" or die "Cannot open $file: $!"; $line = <CFILE>; chomp($line); $address = $line; $line = <CFILE>; chomp($line); $subject = $line; print "mail -s \"$subject\" $address\n"; `/usr/bin/mail -s "$subject" $address < $filename`; close(CFILE); } closedir(JDE);
While I’m sure this is pretty poor compared to what you guys can do, it mostly works but it doesn’t have the subject in the emails.
The other thing that I need to add to this is getting some text into the email and having the csv file as an attachment. This text would be the same for all emails.
Any tips, upgrades, etc would be much appreciated.

In reply to File processing/email program by jwood_70

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.