Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

utl_smtp attachment

Ganesh SrivatsavAug 14 2007 — edited Aug 14 2007
Hi,

I am using the following procedure to send an email everyday with the results of a query.

I know that we can send attachments through utl_smtp. but what I want is that I want to send the result of my query as an attachment without invoking another procedure to append these results into a text file.

So I want to send as an attachment at runtime and put the results into text file dynamically.

Or is there any way to send the message as an attachment of text file?

DECLARE
l_mailhost VARCHAR2(64) := 'localhost';
l_from VARCHAR2(64) := 'support@ganesh.com';
l_subject VARCHAR2(64) := 'Test Mail';
l_to VARCHAR2(64) := 'ganeshsrivatsav@yahoo.com';
l_mail_conn UTL_SMTP.connection;
BEGIN
l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
UTL_SMTP.helo(l_mail_conn, l_mailhost);
UTL_SMTP.mail(l_mail_conn, l_from);
UTL_SMTP.rcpt(l_mail_conn, l_to);

UTL_SMTP.open_data(l_mail_conn);

UTL_SMTP.write_data(l_mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'From: ' || l_from || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || l_subject || Chr(13));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || l_to || Chr(13));
UTL_SMTP.write_data(l_mail_conn, '' || Chr(13));

For i in (select 'ASSET_ID: '||asset_id||','||'VPATH: '||vpath||', '||'TITLE: '||title||', '||'CREATED: '||create_dt||', '||'UPDATED: '||update_dt as col1 from (select asset_id,vpath,title,create_dt,update_dt from asset as of timestamp(sysdate)
minus
select asset_id,vpath,title,create_dt,update_dt from asset as of timestamp(sysdate-1) )) Loop
UTL_SMTP.write_data(l_mail_conn, i.col1 || Chr(13));
End Loop;
UTL_SMTP.close_data(l_mail_conn);

UTL_SMTP.quit(l_mail_conn);
END;
/


Any ideas?

Thanks,

G.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 11 2007
Added on Aug 14 2007
5 comments
4,270 views