Re: How to send pdf as attachment with email in oracle

From: Mladen Gogala <gogala.mladen_at_gmail.com>
Date: Mon, 26 Jan 2015 17:59:19 +0000 (UTC)
Message-ID: <pan.2015.01.26.17.59.51_at_gmail.com>


On Mon, 26 Jan 2015 02:00:55 -0800, wE|rd0 wrote:

> I am successfully receiving email through Oracle but opening the pdf
> file, I get the error:-
> "Adobe Reader could not open "ExistingFile.pdf" because it is either not
> a supported file type or because the file has been damaged(for example,
> it was sent as an email attachment and wasn't correctly decoded).
>
> Below is the code that I am using:-
>
> create or replace PROCEDURE mail_attachments_new
>
> AS
> v_From VARCHAR2(80) := 'payslip_at_companyname.com'; v_Recipient
> VARCHAR2(80) := 'amir.diwan_at_companyname.com';
> v_Subject VARCHAR2(80) := 'test subject';
> v_Mail_Host VARCHAR2(30) := '193.10.10.3';
> v_Mail_Conn utl_smtp.Connection;
> crlf VARCHAR2(2) := chr(13)||chr(10);
>
> BEGIN
>
> v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
>
> utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
>
> utl_smtp.Mail(v_Mail_Conn, v_From);
>
> utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
>
> utl_smtp.Data(v_Mail_Conn,
> 'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf
> ||
> 'From: ' || v_From || crlf ||
> 'Subject: '|| v_Subject || crlf ||
> 'To: ' || v_Recipient || crlf ||
>
> 'MIME-Version: 3.1'|| crlf || -- Use MIME mail standard
> 'Content-Type: multipart/mixed;'|| crlf ||
> ' boundary="-----SECBOUND"'|| crlf ||
> crlf ||
>
> '-------SECBOUND'|| crlf ||
> 'Content-Type: text/plain;'|| crlf ||
> 'Content-Transfer_Encoding: 7bit'|| crlf ||
> crlf ||
> 'some message text'|| crlf || -- Message body 'more message
text'||
> crlf ||
> crlf ||
>
> '-------SECBOUND'|| crlf ||
> 'Content-Type: application/pdf;'|| crlf ||
> ' name="C:\Email\ExistingFile.pdf"'|| crlf ||
> 'Content-Transfer_Encoding: base64'|| crlf ||
> 'Content-Disposition: attachment;'|| crlf ||
> ' filename="ExistingFile.pdf"'|| crlf ||
> -- crlf ||
> -- 'PDF,file,attachement'|| crlf || -- Content of attachment
> -- crlf ||
>
> '-------SECBOUND--' -- End MIME mail
>
> );
>
> utl_smtp.Quit(v_mail_conn);
> EXCEPTION
> WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
> raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
>
> END mail_attachments_new;
>
> Any ideas how to fix it?
>
> Dont have the option of attaching a file. Otherwise, I would have
> attached the snapshot of the error.

You should use UTL_MAIL, which has an option for adding attachments. The procedure name is SEND_ATTACH_RAW.

-- 
Mladen Gogala
The Oracle Whisperer
http://mgogala.byethost5.com
Je suis Charlie
Received on Mon Jan 26 2015 - 18:59:19 CET

Original text of this message