I'm new to PERL. I want to create a PERL Script that could send mail by taking all required fields from an input file present at desktop and can send a mail to everyone in mailing list (separated by comma) accordingly.
Contents of my input data file is as follows:
Recipients are enclosed between tags TO & ENDTO.
Subject of mail is enclosed between SUBJECT & ENDSUBJECT.
Body of mail is enclosed between BODY & ENDBODY.
Sample data file :
TO
rahul@example.com,you@everyone.com
ENDTO
SUBJECT
Weekly status snapshot for WW-5
ENDSUBJECT
BODY
Hi All,
Weekly progress snapshot for this week will be taken on Thursday, 30 Jan at the end of the day. ( Please update your status before the snapshot)
Use work week number as 5 for this week's updates .
Note : If you want any additional data to be picked up ( or dropped ) from your sheets, do work with me so that status collation script can be updated to do this .
Thanks ,
-Ram
ENDBODY
Till now I'm using a code that takes inputs from two different files ("message.txt" & "recipients.txt") and sends mail accordingly. But now I want to parse data from a single file separated by tag fields for recipients, body and subject.
$mailprog = "/usr/sbin/sendmail";
my $file1 = 'message';
open my $ifh1, '<', $file1;
local $/ = undef;
my $contents = <$ifh1>;
my $file2 = 'recipients';
open my $ifh2, '<', $file2;
local $/ = undef;
my $recip = <$ifh2>;
close( $ifh2 );
close( $ifh1 );
$subject= "Weekly status snapshot for WW-3";
open(MAIL, "|$mailprog -t");
print MAIL "To: $recip \n";
#print MAIL "bcc: rahul.agarwal\@everyone.com\n";
print MAIL "From: rahul.agarwal\@everyone.com\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$contents";
close(MAIL);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.