How to send pdf as attachment with email in oracle
Date: Mon, 26 Jan 2015 02:00:55 -0800 (PST)
Message-ID: <63c1ad81-f224-4da8-9059-0c91950e932b_at_googlegroups.com>
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 ||
crlf ||
'some message text'|| crlf || -- Message body
'more message text'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'-------SECBOUND--' -- End MIME mail
);
utl_smtp.Quit(v_mail_conn);
'Content-Type: application/pdf;'|| crlf ||
' name="C:\Email\ExistingFile.pdf"'|| crlf ||
'Content-Transfer_Encoding: base64'|| crlf ||
'Content-Disposition: attachment;'|| crlf ||
' filename="ExistingFile.pdf"'|| crlf ||
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. Received on Mon Jan 26 2015 - 11:00:55 CET