0

I have a file on local drive let's say C:\test\att.csv. I had configured PL/SQL procedure to gather data from database and send an email. The att.csv file contains some values which I have send as an attachment of the email. Can you please help me how to do that. Below is my current code.

EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''abcd.abc.ab''';
  UTL_MAIL.send(sender => 'XXX@abc.com',
            recipients => 'xxx@abc.com',
               subject => 'Test Databases'',
               message =>  v_htmlbody,
               mime_type => 'text/html; charset=us-ascii');

1 Answers1

0
  1. To send an attachment using UTL_MAIL you need to use either UTL_MAIL.send_attach_raw or UTL_MAIL.send_attach_varchar2. Refer to https://docs.oracle.com/database/121/ARPLS/u_mail.htm#ARPLS71208 for the parameters to pass, including attachment and att_filename. These procedures require that the data for the attachment is available in a RAW or VARCHAR2 format.

  2. If the attachment is on the local disk on the database server, you can load the data using UTL_FILE. Refer to: https://docs.oracle.com/database/121/ARPLS/u_file.htm#ARPLS069

Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
  • Hi Jeffrey, appreciate your response. I had gone through theses article earlier. I am only confused how to combine my code (given above) with file attachment logic. Because my file is already on disk and I just need to send it as attachment of the email.If you can give me an example of using attachments with my current code then it would be great. – Kaushal Dave Nov 15 '17 at 07:45
  • Your code doesn't call the correct procedure to send an attachment, and it doesn't load any data from a file. Use UTL_FILE to load the data. – Jeffrey Kemp Nov 15 '17 at 07:50
  • Thanks Jeffery, let me check on it. I will get back to you on this. – Kaushal Dave Nov 15 '17 at 08:14