utl_smtp attachment
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.