Sendmail, mail etc

Pourriez vous me filer un coup de main ?
Je cherche à envoyer un fichier tar.gz en fichier attaché dans un mail. Il faut que cela puisse être exécuté en ligne de commande (en fait dans une commande cron).

Quelqu’un a une solution ?

hum ca te tente le perl ?

bah, moyen, mais si c’est la seule solution …

bouge pas :

my $msg = new MIME::Lite
From =>‘’,
To =>‘’,
Cc =>‘,’,
Subject =>‘A message with 2 parts…’,
Type =>‘multipart/mixed’;

Ajout des pieces attachées

Chaque “attach” a les memes arguments que “new”:

attach $msg
Type =>‘TEXT’,
Data =>“Here’s the GIF file you wanted”;
attach $msg
Type =>‘image/gif’,
Path =>‘aaa000123.gif’,
Filename =>‘logo.gif’;


et tu dois pouvoir le faire tenir en une ligne …

MIME lite n’est pas installé sur mon serveur.
Je vais me débrouiller autrement, je n’ai pas le temps.
Merci de l’aide

19:26:27·nextgens·~ »mail-files --help

with OPTION in:
  --help   display this help and exit
  --version output version information and exit

  -x   trace script

Ca a l’air fait pour…

Tu pourrais t’inspirer de cet excellent script qui sert à effectuer un backup de sa BDD et à l’envoyer par mail, en ne faisant que visitier une page (ce qui se fait très bien par un cron).

<?php [/b] /* Database Backup Utility 1.0 By Eric Rosebrock, [u] [/u] Written: July 7th, 2002 12:59 AM If running from shell, put this above the <?php "#! /usr/bin/php -q" without the quotes!!! This script is dedicated to "Salk". You know who you are [img]style_emoticons/<#EMO_DIR#>/smile.gif[/img] This script runs a backup of your database that you define below. It then gzips the .sql file and emails it to you or ftp's the file to a location of your choice. It is highly recommended that you leave gzip on to reduce the file size. You must chown the directory this script resides in to the same user or group your webserver runs in, or CHMOD it to writable. I do not recommend chmod 777 but it's a quick solution. If you can setup a cron, you can probably chown your directory! IMPORTANT!!! I recommend that you run this outside of your web directory, unless you manually want to run this script. If you do upload it inside your web directory source tree, I would at least apply Apache access control on that directory. You don't want people downloading your raw databases! This script is meant to be setup on a crontab and run on a weekly basis You will have to contact your system administrator to setup a cron tab for this script Here's an example crontab: 0 0-23 * * * php /path/to/thisdirectory/dbsender.php > dev/null */ // configure your database variables below: $dbhost = 'localhost'; // Server address of your MySQL Server $dbuser = 'root'; // Username to access MySQL database $dbpass = ''; // Password to access MySQL database $dbname = 'mydb'; // Database Name // Optional Options You May Optionally Configure $use_gzip = "yes"; // Set to No if you don't want the files sent in .gz format $remove_sql_file = "yes"; // Set this to yes if you want to remove the .sql file after gzipping. Yes is recommended. $remove_gzip_file = "yes"; // Set this to yes if you want to delete the gzip file also. I recommend leaving it to "no" // Configure the path that this script resides on your server. $savepath = "/home/www/dbsender"; // Full path to this directory. Do not use trailing slash! $send_email = "yes"; // Do you want this database backup sent to your email? Fill out the next 2 lines $to = ""; // Who to send the emails to $from = ""; // Who should the emails be sent from? $senddate = date("j F Y"); $subject = "MySQL Database Backup - [b]$senddate[/b]"; // Subject in the email to be sent. $message = "Your MySQL database has been backed up and is attached to this email"; // Brief Message.   $use_ftp = "no"; // Do you want this database backup uploaded to an ftp server? Fill out the next 4 lines $ftp_server = "localhost"; // FTP hostname $ftp_user_name = "ftp_username"; // FTP username $ftp_user_pass = "ftp_password"; // FTP password $ftp_path = "/"; // This is the path to upload on your ftp server! // Do not Modify below this line! It will void your warranty! $date = date("mdy-hia"); $filename = "[b]$savepath[/b]/[b]$dbname[/b]-[b]$date[/b].sql"; passthru("mysqldump --opt -h[b]$dbhost[/b] -u[b]$dbuser[/b] -p[b]$dbpass[/b] [b]$dbname[/b] >[b]$filename[/b]"); [b]if[/b]($use_gzip=="yes"){ $zipline = "tar -czf ".$dbname."-".$date."_sql.tar.gz [b]$dbname[/b]-[b]$date[/b].sql"; shell_exec($zipline); } [b]if[/b]($remove_sql_file=="yes"){ exec("rm -r -f [b]$filename[/b]"); } [b]if[/b]($use_gzip=="yes"){ $filename2 = "[b]$savepath[/b]/".$dbname."-".$date."_sql.tar.gz"; } [b]else[/b] { $filename2 = "[b]$savepath[/b]/[b]$dbname[/b]-[b]$date[/b].sql"; } [b]if[/b]($send_email == "yes" ){ $fileatt_type = filetype($filename2); $fileatt_name = "".$dbname."-".$date."_sql.tar.gz"; $headers = "From: [b]$from[/b]"; // Read the file to be attached ('rb' = read binary) $file = fopen($filename2,'rb'); $data = fread($file,filesize($filename2)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{[b]$semi_rand[/b]}x"; // Add the headers for a file attachment $headers .= " MIME-Version: 1.0 " ."Content-Type: multipart/mixed; " ." boundary="{[b]$mime_boundary[/b]}""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format. " ."--{[b]$mime_boundary[/b]} " ."Content-Type: text/plain; charset="iso-8859-1" " ."Content-Transfer-Encoding: 7bit " . $message . " "; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{[b]$mime_boundary[/b]} " ."Content-Type: {[b]$fileatt_type[/b]}; " ." name="{[b]$fileatt_name[/b]}" " ."Content-Disposition: attachment; " ." filename="{[b]$fileatt_name[/b]}" " ."Content-Transfer-Encoding: base64 " . $data . " " ."--{[b]$mime_boundary[/b]}-- "; // Send the message $ok = @mail($to, $subject, $message, $headers); [b]if[/b] ($ok) { echo "

Database backup created and sent! File name [b]$filename2[/b]

"; } [b]else[/b] { echo "

Mail could not be sent. Sorry!

"; } } [b]if[/b]($use_ftp == "yes"){ $ftpconnect = "ncftpput -u [b]$ftp_user_name[/b] -p [b]$ftp_user_pass[/b] -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V [b]$ftp_server[/b] [b]$ftp_path[/b] [b]$filename2[/b]"; shell_exec($ftpconnect); echo "

[b]$filename2[/b] Was created and uploaded to your FTP server!

"; } [b]if[/b]($remove_gzip_file=="yes"){ exec("rm -r -f [b]$filename2[/b]"); } [b] ?>[/b]

J’espère que ça te sera utile.