Home » RDBMS Server » Server Administration » sending an attachment file using utl_smtp
sending an attachment file using utl_smtp [message #221527] Tue, 27 February 2007 05:42 Go to next message
M.Shakeel Azeem
Messages: 226
Registered: September 2006
Senior Member
i have created the following procedure for sending email
its working fine but i want to send an attachment file with email and i didn't find any help
Can anybody help me in this regard?

CREATE OR REPLACE PROCEDURE email_from_plsql IS
tmpVar NUMBER;
c UTL_SMTP.CONNECTION;

PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
BEGIN
UTL_SMTP.WRITE_DATA(c, name || ': ' || header || UTL_TCP.CRLF);
END;
BEGIN
-- Open connection to SMTP gateway
c := UTL_SMTP.OPEN_CONNECTION('192.168.0.12',25);
UTL_SMTP.HELO(c, '192.168.0.12');
UTL_SMTP.MAIL(c, 'mshakeel@nctex.com');
UTL_SMTP.RCPT(c, 'mshakeel@nctex.com');
UTL_SMTP.RCPT(c, 'afzaal@nctex.com');
UTL_SMTP.OPEN_DATA(c);
send_header('From','mshakeel@nctex.com');
send_header('To','mshakeel@nctex.com');
send_header('Cc','afzaal@nctex.com');
send_header('Subject','Automated Database Email');
UTL_SMTP.WRITE_DATA(c, utl_tcp.CRLF || 'This is an automated email from the Oracle database.');
UTL_SMTP.WRITE_DATA(c, utl_tcp.CRLF || 'The database is working for you!');
UTL_SMTP.CLOSE_DATA(c);
UTL_SMTP.QUIT(c);
EXCEPTION
WHEN NO_DATA_FOUND THEN
Null;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END email_from_plsql;
/

Re: sending an attachment file using utl_smtp [message #221605 is a reply to message #221527] Tue, 27 February 2007 11:45 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
> i want to send an attachment file with email and i didn't find any help
I am not surprised.
In reality (& under the hood) there is no such thing as attachment.
Any "attachment" is simply a specially encoded section contained in the body of the message; which email client s/w know how to present.
While it can be done via PL/SQL, I am not sure it is worth the effort to reinvent the wheel.
When I had to meet similar requirements, I wrote my solution in PERL; which has email extensions to easily do attachments.
Previous Topic: ORA-00607
Next Topic: help plz
Goto Forum:
  


Current Time: Mon Dec 02 15:28:13 CST 2024