niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle » Tools
Emailing pdf files using utl_smtp questions
Post new topic   Reply to topic Page 1 of 1 [6 Posts] View previous topic :: View next topic
Author Message
Sybrand Bakker
*nix forums Guru


Joined: 03 Apr 2005
Posts: 1766

PostPosted: Tue Jul 11, 2006 5:23 pm    Post subject: Re: Emailing pdf files using utl_smtp questions Reply with quote

On 11 Jul 2006 06:58:27 -0700, "hah" <shhoff8@yahoo.com> wrote:

Quote:
Unfortunately database is 9, I saw the UTL_MAIL seemed much easier to
work with!


Please stop top posting.

--
Sybrand Bakker, Senior Oracle DBA
Back to top
hah
*nix forums beginner


Joined: 01 Mar 2006
Posts: 4

PostPosted: Tue Jul 11, 2006 1:59 pm    Post subject: Re: Emailing pdf files using utl_smtp questions Reply with quote

Thank you very much, I will give that a try!

Frank van Bortel wrote:
Quote:
asktom.oracle.com
search for "email" and for "dirlist"
The first will give you the solution for attachments,
the second provides a java/pl/sql solution of reading
directories (thus: your exact file names)

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...
Back to top
hah
*nix forums beginner


Joined: 01 Mar 2006
Posts: 4

PostPosted: Tue Jul 11, 2006 1:58 pm    Post subject: Re: Emailing pdf files using utl_smtp questions Reply with quote

Unfortunately database is 9, I saw the UTL_MAIL seemed much easier to
work with!

DA Morgan wrote:
Quote:
hah wrote:
I am using web version. I run a bunch of reports to files on the
server which the web version appends numbers to the end of the file
name. I'm having 2 problems:

First how do I get the code to recognize wildcards. I won't know the
numbers that the server appends to the filenames and I need to identify
the filename that corresponds to our employee id to send them the
correct report. Can wildcards be used in bfilename?

Also when I specify the exact filename the loop works and sends out the
pdf attachment email but only the first one is ok, all the other pdf's
are corrupt and adobe says it is not correctly decoded. ANY help would
be greatly appreciated! I am new to the web version as well as using
utl_smtp and bfile.

What version of Oracle?

If 10g you should be using UTL_MAIL not UTL_SMTP.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Back to top
psoug
*nix forums Guru


Joined: 15 May 2005
Posts: 3492

PostPosted: Mon Jul 10, 2006 7:48 pm    Post subject: Re: Emailing pdf files using utl_smtp questions Reply with quote

hah wrote:
Quote:
I am using web version. I run a bunch of reports to files on the
server which the web version appends numbers to the end of the file
name. I'm having 2 problems:

First how do I get the code to recognize wildcards. I won't know the
numbers that the server appends to the filenames and I need to identify
the filename that corresponds to our employee id to send them the
correct report. Can wildcards be used in bfilename?

Also when I specify the exact filename the loop works and sends out the
pdf attachment email but only the first one is ok, all the other pdf's
are corrupt and adobe says it is not correctly decoded. ANY help would
be greatly appreciated! I am new to the web version as well as using
utl_smtp and bfile.

What version of Oracle?

If 10g you should be using UTL_MAIL not UTL_SMTP.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Back to top
frank.van.bortel@gmail.co
*nix forums Guru


Joined: 11 Sep 2005
Posts: 832

PostPosted: Mon Jul 10, 2006 6:57 pm    Post subject: Re: Emailing pdf files using utl_smtp questions Reply with quote

asktom.oracle.com
search for "email" and for "dirlist"
The first will give you the solution for attachments,
the second provides a java/pl/sql solution of reading
directories (thus: your exact file names)

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...
Back to top
hah
*nix forums beginner


Joined: 01 Mar 2006
Posts: 4

PostPosted: Mon Jul 10, 2006 6:47 pm    Post subject: Emailing pdf files using utl_smtp questions Reply with quote

I am using web version. I run a bunch of reports to files on the
server which the web version appends numbers to the end of the file
name. I'm having 2 problems:

First how do I get the code to recognize wildcards. I won't know the
numbers that the server appends to the filenames and I need to identify
the filename that corresponds to our employee id to send them the
correct report. Can wildcards be used in bfilename?

Also when I specify the exact filename the loop works and sends out the
pdf attachment email but only the first one is ok, all the other pdf's
are corrupt and adobe says it is not correctly decoded. ANY help would
be greatly appreciated! I am new to the web version as well as using
utl_smtp and bfile.

DECLARE
fil BFILE;
file_len PLS_INTEGER;
MAX_LINE_WIDTH PLS_INTEGER := 54;
buf RAW(2100);
amt BINARY_INTEGER := 672 * 3; /* ensures proper format; 2016 */
pos PLS_INTEGER := 1; /* pointer for each piece */
filepos PLS_INTEGER := 1; /* pointer for the file */
filenm VARCHAR2(50);
v_file_name VARCHAR2(100) := 'aa.csv'; /* ascii file attachment */
v_file_handle UTL_FILE.FILE_TYPE;
v_directory_name VARCHAR2(100) := 'BFILE_DIR';
v_line VARCHAR2(1000);
conn UTL_SMTP.CONNECTION;
mesg VARCHAR2(32767);
mesg_len NUMBER;
crlf VARCHAR2(2) := chr(13) || chr(10);
data RAW(2100);
chunks PLS_INTEGER;
len PLS_INTEGER := 1;
modulo PLS_INTEGER;
pieces PLS_INTEGER;
err_num NUMBER;
err_msg VARCHAR2(100);
v_mime_type_bin varchar2(30) := 'application/pdf';

CURSOR emp_cursor is
SELECT emp_num,email from test_email;

enum varchar2(5);
email varchar2(50);
wild varchar2(2) := '%';
tdate date;

BEGIN
open emp_cursor;
LOOP
FETCH emp_cursor into enum,email;
EXIT WHEN (emp_cursor%NOTFOUND);

tdate := '01-JAN-2006';
filenm := enum||tdate||wild||'.pdf';


BEGIN

conn := demo_mail.begin_mail(sender => 'test@test.com',
recipients => email,subject => 'Missing Timesheet Report',
mime_type => demo_mail.MULTIPART_MIME_TYPE);
END begin_mail;
BEGIN
demo_mail.attach_text(conn => conn,data => '<h1>Attachment is
Working</h1>' || crlf || crlf,mime_type => 'text/html');
END attach_text;
BEGIN
demo_mail.begin_attachment(conn => conn,mime_type =>
'text/plain',inline => TRUE,filename => v_file_name,
transfer_enc => '7 bit');
begin
v_file_handle := utl_file.fopen(v_directory_name, v_file_name, 'r');
loop
utl_file.get_line(v_file_handle, v_line);
mesg := v_line || crlf;
demo_mail.write_text(
conn => conn,
message => mesg);
end loop;
exception
when others then
null;
end;
utl_file.fclose(v_file_handle);
demo_mail.end_attachment(
conn => conn );
END begin_attachment;
BEGIN
demo_mail.begin_attachment(conn => conn,mime_type =>
v_mime_type_bin,inline => TRUE,filename => filenm, transfer_enc =>
'base64');
BEGIN
fil := BFILENAME('BFILE_DIR', filenm);
dbms_output.put_line(filenm);
file_len := dbms_lob.getlength(fil);
modulo := mod(file_len, amt);
pieces := trunc(file_len / amt);
if (modulo <> 0) then
pieces := pieces + 1;
end if;
dbms_lob.fileopen(fil, dbms_lob.file_readonly);
dbms_lob.read(fil, amt, filepos, buf);
data := NULL;
FOR i IN 1..pieces LOOP
filepos := i * amt + 1;
file_len := file_len - amt;
data := utl_raw.concat(data, buf);
chunks := trunc(utl_raw.length(data) / MAX_LINE_WIDTH);
IF (i <> pieces) THEN
chunks := chunks - 1;
END IF;
demo_mail.write_raw( conn => conn,
message => utl_encode.base64_encode(data ) );
data := NULL;
if (file_len < amt and file_len > 0) then
amt := file_len;
end if;
dbms_lob.read(fil, amt, filepos, buf);
END LOOP;
END;


dbms_lob.fileclose(fil);
demo_mail.end_attachment(conn => conn );
END begin_attachment;
demo_mail.end_mail(conn => conn);


END LOOP;
close emp_cursor;

EXCEPTION
when no_data_found then
demo_mail.end_attachment( conn => conn );
dbms_lob.fileclose(fil);
when others then
demo_mail.end_attachment( conn => conn );
err_num := SQLCODE;
err_msg := SUBSTR(SQLERRM, 1, 100);
dbms_output.put_line('Error number is ' || err_num);
dbms_output.put_line('Error message is ' || err_msg);
dbms_lob.fileclose(fil);
END sendit;
/
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [6 Posts] View previous topic :: View next topic
The time now is Sat Nov 22, 2008 2:05 am | All times are GMT
navigation Forum index » Databases » Oracle » Tools
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Net:TFTPd questions - Want to upload configs via TFTP Adam Perl 0 Thu Jul 20, 2006 4:59 pm
No new posts Net:TFTPd questions - Want to upload configs via TFTP Adam modules 1 Thu Jul 20, 2006 4:29 pm
No new posts Questions on bitfields and struct sarathy C 3 Thu Jul 20, 2006 1:58 pm
No new posts SLED 10 Questions Moif Murphy Suse 2 Thu Jul 20, 2006 12:11 pm
No new posts howto log in from one bsd-server to another and move file... Tobias Steer FreeBSD 3 Thu Jul 20, 2006 10:02 am

Mortgages | Books | Mortgage Calculator | Anime | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 1.1568s ][ Queries: 20 (1.0387s) ][ GZIP on - Debug on ]