Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

1) Gets all the user info and adds it to a data file w/ error checking -this part is done.

2) Send an email to remind person of the date, one day prior to event.

I only recently started to learn perl and dont know how difficult a task this would be. Thanking you in advance A confused -Aiursrage

justinsaw@hotmail.com

edit by mirod: changed the title and added p tags

  • Comment on how do I issue e-mail using perl? (was:Help)

Replies are listed 'Best First'.
(jeffa - sending mail) Re: Help
by jeffa (Bishop) on Dec 06, 2000 at 21:25 UTC
    Easy if you can install CPAN modules:
    use strict; use Mail::Mailer; my $mailer = Mail::Mailer->new(); $mailer->open({ From => $from_address, To => $to_address, Subject => $subject, }) or die "Can't open: $!\n"; print $mailer $body; $mailer->close();
    or directly with sendmail:
    open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n"; print SENDMAIL <<"EOF"; From: User Originating Mail <me\@host> To: Final Destination <you\@otherhost> Subject: A relevant subject line Body of the message goes here, in as many lines as you like. EOF close(SENDMAIL) or warn "sendmail didn't close nicely";
    This was taken directly from the Perl Cookbook page 651. Go buy it!

    The first one uses the CPAN module Mail::Mailer, there are lot's of other CPAN modules that send mail for you, such as Mail::Sendmail.

    Use the second method __ONLY__ if you can't install CPAN modules on your school's computer, which you probably can't. Since this looks like a homework question, please do some studying and don't just cargo cut-n-hack. You'll probably be tested on this anyway. :)

    Jeff

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    F--F--F--F--F--F--F--F--
    (the triplet paradiddle)
    
Re: Help
by marius (Hermit) on Dec 06, 2000 at 21:44 UTC
    Another thing to find out would be how your putting the date into the data file. That's something we would need to know to figure out the "prior date" portion.

    I can't come up with a quick non-CPAN way to do that to cover Dec 31 -> Jan 1 changes, and also lastday(month)->firstday(nextmonth) changes.

    Any folks have any ideas on how to parse the date, assuming they're stored as MM/DD/YYYY (if they're separated fields, they can be join()'d, and if DD/MM/YYYY or some other format, it should be easily changable to MM/DD/YYYY)? Dates are probably one of the most irritating things when it comes to programming. =]

    -marius
      I think this will do the trick:
      use strict; use Time::Local; my $time = timelocal(localtime); $time -= (60 * 60 * 24); # subtract one day my ($s, $min, $h, $d, $mon, $y, $w, $yd, $isdst) = localtime($time); printf("Yesterday's date: %02d:%02d:%02d-%04d/%02d/%02d\n", $h, $min, $s, $y+1900, $mon+1, $d);
      The trick is to work in Epoch seconds, and let localtime figure out what the date is.

      Jeff

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      F--F--F--F--F--F--F--F--
      (the triplet paradiddle)