|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
email with attachment
want to add code to this to send me the file
it's a backup db this works great but I want to add the code so it sends me the new file every night once it makes it code:-------------------------------------------------------------------------------- mysqldump -u dbuser -pdbuserpassword --opt dbname > /home/youraccount/dbbackup.sql gzip /home/youraccount/dbbackup.sql mv /home/youraccount/dbbackup.sql.gz /home/youraccount/dbbackup-`date +%m-%d-%Y`.sql.gz ---------------------------------------------------------------------------------------file name is dbbackup.pl--------------------------------------------------- now I thought adding sendmail= name@domain dbbackup-`date +%m-%d-%Y`.sql.gz would work but not sure but think I need a right way to do it need to email an attachment I'm a newbie at this can someone help please ![]() |
|
#2
|
|||
|
|||
|
Hello you can use the following code to send an email
with an attachment. Code:
#!/usr/bin/perl
use MIME::Entity;
$message = "Message text here";
### Create the top-level, and set up the mail headers:
$top = MIME::Entity->build(Type =>"multipart/mixed",
From => "from\@yourdomain.com",
To => "to\@yourdomain.com",
Subject => "Your subject here");
$top->attach(Data=>$message);
### Part #2: a GIF file:
$top->attach(Path => "/path/to/file/to/attach.zip",
Type => "application/gzip",
Encoding => "binary");
### Send it:
open MAIL, "| /usr/lib/sendmail -t -oi -oem" or die "open: $!";
$top->print(\*MAIL);
close MAIL;
Hope this helps. Regards, Ray |
|
#3
|
|||
|
|||
|
ok only one question
the backup file gets the name with data every night so how would I list the in the file to attach ? would it be like this ### Part #2: a GIF file: $top->attach(Path => "/home/xxx/dbbackup-`date +%m-%d-%Y`.sql.gz", Type => "application/gzip", Encoding => "binary"); |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > email with attachment |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|