#!/usr/bin/perl use strict; use DBI; use Net::SMTP; use utf8; my @addr_to_send = qw/anton.harris@beirtelecom.com/; my $from_addr = 'systemplus@joursheureux.be'; my $smtp_addr = 'smtp.skynet.be'; my $csvfile = "appelerr.csv"; ... # gets info from a database, creates a CSV file foreach my $to_send (@addr_to_send) { print "Sending mail to $to_send\n"; my $smtp = Net::SMTP->new($smtp_addr); $smtp->mail($from_addr); $smtp->to($to_send); $smtp->data(); $smtp->datasend("Subject: Appels S+ erronés"); $smtp->datasend("\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed; boundary=\"frontier\"\n"); $smtp->datasend("--frontier\n"); $smtp->datasend("Content-type: text/plain\n"); $smtp->datasend("Explication sur cet e-mail :\n"); $smtp->datasend("Cet e-mail contient la liste des appels effectués par les pensionnaires et qui ne se sont pas terminés normalement.\n"); $smtp->datasend("Il peut s'agir d'un moment où l'infirmière a pu résoudre les raisons de l'appel sans devoir appeler la chambre,\n"); $smtp->datasend("puis effectue un reset, ou que le pensionnaire, impatient, sonne de manière répétitive,\n"); $smtp->datasend("mais cela peut également etre un temps de réponse beaucoup trop long.\n\n"); if ($#badcalls < 0) { $smtp->datasend("Aucun appel erroné n'a été détecté.\n"); } else { for (sort @badcalls) { print "Bad call in line : $_ : $dbtime$_ - $dbroomid$_ - $dbevent$_\n"; $smtp->datasend("$dbtime$_ - numèro de local : $rooms{$dbroomid$_}\n"); } # THIS IS WHERE THE ATTACHMENT IS DONE $smtp->datasend("--frontier\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$csvfile\"\n"); $smtp->datasend("Content-Type: application/text; name= $csvfile "); $smtp->datasend("\n"); open CSVFH, "< $csvfile"; while () { chomp; $smtp->datasend("$_\n"); } close CSVFH; } $smtp->datasend("--frontier--\n"); $smtp->dataend(); $smtp->quit; }