Home » Fusion Middleware & Colab Suite » Weblogic & Application Server » Attachment through emails..
Attachment through emails.. [message #76544] |
Mon, 25 November 2002 23:04 |
Deepak Khemani
Messages: 5 Registered: April 2002
|
Junior Member |
|
|
Hi all .. I have a urgent requirement to send attachment in emails. I was able to send message using UTL_SMTP . I want to run a batch process to send emails with a PDF file as attachment.
Deepak
|
|
|
Re: Attachment through emails.. [message #76545 is a reply to message #76544] |
Tue, 26 November 2002 00:04 |
Golasa Taheri
Messages: 4 Registered: October 2002
|
Junior Member |
|
|
We use procedure below in our application ,this procedure check the mail server properties and services then establish the connection between Web server and Mail server:
======================================
create or replace procedure mail_files
( from_name varchar2 ,
to_name varchar2 ,
subject varchar2 ,
message varchar2 ,
max_size number default 99999,
filename1 varchar2
) is
v_smtp_server varchar2(20) := 'Ip Address Of Mail Server';
v_smtp_server_port number := 25;
v_directory_name varchar2(100);
v_file_name varchar2(100);
v_line varchar2(1000);
crlf varchar2(2):= chr(13) || chr(10);
mesg varchar2(32767);
conn UTL_SMTP.CONNECTION;
type varchar2_table is table of varchar2(200) index by binary_integer;
file_array varchar2_table;
i binary_integer;
v_file_handle utl_file.file_type;
v_slash_pos number;
mesg_len number;
mesg_too_long exception;
invalid_path exception;
mesg_length_exceeded boolean := false;
begin
-- first load the three filenames into an array for easier handling later ...
file_array(1) := filename1;
-- Open the SMTP connection ...
-- ------------------------
conn:= utl_smtp.open_connection( v_smtp_server, v_smtp_server_port );
-- Initial handshaking ...
-- -------------------
utl_smtp.helo( conn, v_smtp_server );
utl_smtp.mail( conn, from_name );
utl_smtp.rcpt( conn, to_name );
utl_smtp.open_data ( conn );
-- build the start of the mail message ...
-- -----------------------------------
mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
'From: ' || from_name || crlf ||
'Subject: ' || subject || crlf ||
'To: ' || to_name || crlf ||
'Mime-Version: 1.0' || crlf ||
'--DMW.Boundary.605592468' || crlf ||
'Content-Type: text/html; charset=window-1256' || crlf ||
'Content-Transfer-Encoding: 7bit' || crlf ||
message || crlf ;
mesg_len := length(mesg);
if mesg_len > max_size then
mesg_length_exceeded := true;
end if;
utl_smtp.write_data ( conn, mesg );
-- Append the files ...
-- ----------------
--for i in 1..3 loop
-- Exit if message length already exceeded ...
--exit when mesg_length_exceeded;
-- If the filename has been supplied ...
if file_array(1) is not null then
-- locate the final '/' or '' in the pathname ...
v_slash_pos := instr(file_array(1), '/', -1 );
if v_slash_pos = 0 then
v_slash_pos := instr(file_array(1), '', -1 );
end if;
-- separate the filename from the directory name ...
v_directory_name := substr(file_array(1), 1, v_slash_pos - 1 );
v_file_name := substr(file_array(1), v_slash_pos + 1 );
-- open the file ...
v_file_handle := utl_file.fopen(v_directory_name, v_file_name, 'r' );
-- generate the MIME boundary line ...
mesg := crlf || '--DMW.Boundary.605592468' || crlf ||
'Content-Type: text/html; charset="window-1256"; name="' || v_file_name || '"' || crlf ||
'Content-Disposition: attachment; filename="' || v_file_name || '"' || crlf ||
'Content-Transfer-Encoding: quoted-printable' || crlf || crlf ;
mesg_len := mesg_len + length(mesg);
utl_smtp.write_data ( conn, mesg );
-- and append the file contents to the end of the message ...
loop
begin
utl_file.get_line(v_file_handle, v_line);
exception when no_data_found then exit;
end;
if mesg_len + length(v_line) > max_size then
mesg := '*** truncated ***' || crlf;
utl_smtp.write_data ( conn, mesg );
mesg_length_exceeded := true;
raise mesg_too_long;
end if;
mesg := v_line || crlf;
utl_smtp.write_data ( conn, mesg );
mesg_len := mesg_len + length(mesg);
end loop;
mesg := crlf;
utl_smtp.write_data ( conn, mesg );
-- close the file ...
utl_file.fclose(v_file_handle);
end if;
--end loop;
-- append the final boundary line ...
mesg := crlf || '--DMW.Boundary.605592468--' || crlf;
utl_smtp.write_data ( conn, mesg );
-- and close the SMTP connection ...
utl_smtp.close_data( conn );
utl_smtp.quit( conn );
end;
======================================
after that you must define your path of file in init.ora.
Attention:this file must be in Oracle Directory
in procedure bellow we use mail_files procedure in our code.you can see it in bellow.
+++++++++++++++++++
..............
...............
...............
...............
begin
v_file_handle := utl_file.fopen('f:oracleora9Apachemodplsqlcfg','mail_un.html','w');
utl_file.put(v_file_handle,mail_text);
utl_file.fflush(v_file_handle);
exception when utl_file.invalid_mode then
raise_application_error(-20002,'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
when utl_file.invalid_path then
raise_application_error(-20001,'INVALID_PATH: File location or filename was invalid.');
when utl_file.invalid_filehandle then
raise_application_error(-20002,'INVALID_FILEHANDLE: The file handle was invalid.');
when utl_file.invalid_operation then null;
/*raise_application_error(-20003,'INVALID_OPERATION: The file could not be opened or operated on as requestedddddd.');*/
when utl_file.read_error then
raise_application_error(-20004,'READ_ERROR: An operating system error occurred during the read operation.');
when utl_file.write_error then
raise_application_error(-20005,'WRITE_ERROR: An operating system error occurred during the write operation.');
when utl_file.internal_error then
raise_application_error(-20006,'INTERNAL_ERROR: An unspecified error in PL/SQL.');
end;
mail_files(p_from,p_to,p_subject,p_contents,9999999999,'f:oracleora9Apachemodplsqlcfgmail_un.html');
+++++++++++++++++++
I hope it cpuld help you.........
|
|
|
Goto Forum:
Current Time: Mon Nov 04 18:41:41 CST 2024
|