Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Send Mail in Unix
Tom,
Here is a perl script that will send the file as an attachment.
HTH
Peter
>#!/usr/bin/perl -w
>
>
># mail_attach.pl -- Mail files as attachments
>
>
># Created new perl script mostly from MLB 11/09/1999
># "The Perl Journal 14" mail_attach.pl example
>#
># $ARGV[0]: The sender e-mail address
># $ARGV[1]: Filename with main message in it.
># $ARGV[2]: Filename to attach.
># If >1, separate with commas and *no* spaces
># $ARGV[3]: Subject
># $ARGV[4..$#ARGV]: Destination e-mail addresses.
># If there are spaces in
># an address, then enclose it in quotes
>
>
># use strict;
># use Socket;
> use MIME::Lite;
> use Net::SMTP;
>
>
> my %ending_map = (
> crt => ['application/x-x509-ca-cert' , 'base64'],
> aiff => ['audio/x-aiff' , 'base64'],
> gif => ['image/GIF' , 'base64'],
> txt => ['text/plain' , '8bit'],
> com => ['text/plain' , '8bit'],
> class => ['application/octet-stream' , 'base64'],
> htm => ['text/html' , '8bit'],
> html => ['text/html' , '8bit'],
> htmlx => ['text/html' , '8bit'],
> htx => ['text/html' , '8bit'],
> jpg => ['image/jpeg' , 'base64'],
> dat => ['text/plain' , '8bit'],
> hlp => ['text/plain' , '8bit'],
> ps => ['application/postscript' , '8bit'],
> 'ps-z' => ['application/postscript' , 'base64'],
> dvi => ['application/x-dvi' , 'base64'],
> pdf => ['application/pdf' , 'base64'],
> mcd => ['application/mathcad' , 'base64'],
> mpeg => ['video/mpeg' , 'base64'],
> mov => ['video/quicktime' , 'base64'],
> exe => ['application/octet-stream' , 'base64'],
> zip => ['application/zip' , 'base64'],
> bck => ['application/VMSBACKUP' , 'base64'],
> au => ['audio/basic' , 'base64'],
> mid => ['audio/midi' , 'base64'],
> midi => ['audio/midi' , 'base64'],
> bleep => ['application/bleeper' , '8bit'],
> wav => ['audio/x-wav' , 'base64'],
> xbm => ['image/x-xbm' , '7bit'],
> tar => ['application/tar' , 'base64'],
> imagemap => ['application/imagemap' , '8bit'],
> sit => ['application/x-stuffit' , 'base64'],
> bin => ['application/x-macbase64'],
> hqx => ['application/mac-binhex40' , 'base64'],
> );
>
>
> my $mail_from = shift @ARGV;
> my $message_file = shift @ARGV;
> my @mail_file = split(",", shift(@ARGV));
> my $subject = shift @ARGV;
> my @mail_to = @ARGV;
>
>
> my $logname = getpwuid($<);
> my $logdate = `date`;
> open(LOG,">>/tech/cc/banner/mail_attach.log");
> print LOG "\n";
> print LOG " Date = ",$logdate;
> print LOG " Laurel Username = ",$logname,"\n";
> print LOG " Mail From = ",$mail_from,"\n";
> print LOG " Message file = ",$message_file,"\n";
> print LOG "Attached File(s) = ",@mail_file,"\n";
> print LOG " Subject = ",$subject,"\n";
> print LOG " Mail To = ",@mail_to,"\n";
> print LOG "************************************\n";
> close(LOG);
>
>
> my $mime; # The MIME object
>
>
> # Slurp in the message text and build up the main
> # part of the mail.
> {
> local $/;
> $/ = undef;
> local @ARGV;
> @ARGV = $message_file;
> my $main_message = <>;
> $mime = new MIME::Lite( From => $mail_from,
> To => [@mail_to],
> Subject => $subject,
> Type => 'text/plain',
> Data => $main_message);
> }
>
>
>
>
> foreach (@mail_file) { # Attach each file in turn
> my($type, $ending);
> /.*\.(.+)$/; # Snag the ending
> $ending = $1;
>
>
> # Is it in our list?
> if (exists($ending_map{$ending})) {
> $type = $ending_map{$ending};
> } else {
> $type = ['text/plain', '8bit'];
> }
>
>
> # Attach it to the message
> $mime->attach( Type => $type->[0],
> Encoding => $type->[1],
> Disposition => "attachment",
> Path => $_);
> }
>
>
> # Tell MIME::Lite to use Net::SMTP instead of sendmail.
> MIME::Lite->send('smtp', 'axe', Timeout => 20);
> $mime->send;
At 07:44 AM 02/13/2003 -0800, you wrote:
>All,
>
>I'm trying to send an email attachment (Oracle Tablespace Report) from a Sun
>Unix box to myself when the batch job runs.
>
>Anybody been able to do this? I can send the text of the file, but what I
>really want to do is to send the file (it's an Excel Spreadsheet).
>
>thanks in advance.
>
>Tom Mercadante
>Oracle Certified Professional
>
>--
>Please see the official ORACLE-L FAQ: http://www.orafaq.net
>--
>Author: Mercadante, Thomas F
> INET: NDATFM_at_labor.state.ny.us
>
>Fat City Network Services -- 858-538-5051 http://www.fatcity.com
>San Diego, California -- Mailing list and web hosting services
>---------------------------------------------------------------------
>To REMOVE yourself from this mailing list, send an E-Mail message
>to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>the message BODY, include a line containing: UNSUB ORACLE-L
>(or the name of mailing list you want to be removed from). You may
>also send the HELP command for other information (like subscribing).
Peter Johnson, DBA
Humboldt State University
johnson_at_humboldt.edu
707-826-6122
Those that can give up essential liberty
to obtain a little temporary safety
deserve neither liberty nor safety
- Benjamin Franklin, 1759
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Peter Johnson INET: johnson_at_humboldt.edu Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Thu Feb 13 2003 - 12:54:47 CST