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!

Attaching a file from an oracle directory to an email

Jannette Christie4 days ago — edited 4 days ago

Hi,

I have a PL/SQL package that writes to a file using utl_file, I also want to send an email with the file as an attachment.

mail_text_ varchar2(2000);
file_name_  VARCHAR2(32000);
output varchar2(32000);
attachment_text Clob; 
file_t := utl_file.fopen('DATA_MIGRATION', 'IPIS' || to_char(sysdate,'YYYYMMDD') || '.CSV','R') ;
loop
    begin
      utl_file.get_line(file_t,output);
     attachment_text :=  attachment_text||output||utl_tcp.crlf;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN EXIT;
    end;
       END LOOP; 
      -- dbms_output.put_line(attachment_text);
       UTL_FILE.FCLOSE(file_t);
       
mail_text_ := 'Inventory part in stock report for <b>'||trunc(Sysdate)||'.<br />
<br />
Regards,<br />
IFS<br />
<br />
';

ifsapp.command_sys.Mail(sender_      => ifsapp.fnd_session_api.Get_App_Owner,
                         from_        => 'O365.SMTP@xxxx.co.uk',
                           to_list_     => 'xyz@xyz.co.uk',
                         cc_list_     =>  Null,
                         bcc_list_    => 'xyz@xyz.co.uk',
                         subject_     => 'IPIS daily extract',
                         text_        => to_clob(mail_text_) ,
                         attach_      => to_clob(attachment_text) ,
                         rowkey_      => null,
                         mail_sender_ => null);
utl_file.fremove( 'DATA_MIGRATION', 'IPIS' || to_char(sysdate,'YYYYMMDD') || '.CSV' ) ;

When I run the code I am getting the following error message:

It looks as if there is an issue with the attachment but I cannot work out what the issue is, can anyone advise please ?

Thanks

This post has been answered by Gerrit van der Linden on Jan 23 2026
Jump to Answer
Comments
Post Details
Added 4 days ago
4 comments
85 views