Attach PDF using UTL_SMTP

Hi,
I am trying to attach a pdf file in an email using UTL_SMTP builtin but the when i get the email
and try to open it then Adobe Reader says cannot open as file may be damaged or is not able to decode it.
I am pasting the code i am using below. i read some threads from this forum and some help from google to use this code but now i am not able to figure out what i need to do so please help me.
Regards
declare
p_sender VARCHAR2(100);
p_recipient VARCHAR2(500) := '[email protected]';
p_subject VARCHAR2(500) := 'Test attachement';
p_message VARCHAR2(500) := 'This is email body';
p_filename  VARCHAR2(500) := '/udlpdrop/dev10g/eor/WS_FTP.LOG'; PATELMK_eordetail.pdf';
p_filename VARCHAR2(500) := '/udlpdrop/dev10g/eor/PATELMK_eordetail.pdf';
v_recordkeys eor.exception_log.rec_keys%TYPE;
v_msg VARCHAR2(32000);
p_blob blob;
i integer := 1;
v_raw raw(57);
v_length integer := 0;
v_buffer_size integer := 57;
v_mailconn utl_smtp.connection;
gc_crlf VARCHAR2(4) := chr(13) || chr(10);
gc_lf VARCHAR2(4) := chr(10);
gc_mailhost eor.sys_config.sys_var_value%TYPE := 'ykmail.goldlnk.rootlnka.net';
gc_maildomain eor.sys_config.sys_var_value%TYPE := 'goldlnk.rootlnka.net';
BEGIN
v_mailconn := utl_smtp.open_connection(gc_mailhost,25);
utl_smtp.helo(v_mailconn,gc_mailhost);
utl_smtp.mail(v_mailconn,gc_maildomain);
utl_smtp.rcpt(v_mailconn,p_recipient);
utl_smtp.open_data (v_mailconn);
utl_smtp.write_data(v_mailconn, 'Content-Type' || ': ' || 'application/pdf' || utl_tcp.CRLF);
utl_smtp.write_data( v_mailconn, 'Content-Disposition: attachment; filename="' || p_filename || '"' || utl_tcp.crlf);
utl_smtp.write_data( v_mailconn, 'Content-Transfer-Encoding: base64' || utl_tcp.crlf );
utl_smtp.write_data( v_mailconn, utl_tcp.crlf );
v_length := dbms_lob.getlength(p_blob);
while i < v_length loop
dbms_lob.read( p_blob, v_buffer_size, i, v_raw );
utl_smtp.write_raw_data( v_mailconn, utl_encode.base64_encode(v_raw) );
utl_smtp.write_data( v_mailconn, utl_tcp.crlf );
i := i + v_buffer_size;
end loop while_loop;
utl_smtp.write_data( v_mailconn, utl_tcp.crlf );
utl_smtp.close_data (v_mailconn);
utl_smtp.quit(v_mailconn);
EXCEPTION
WHEN OTHERS THEN
utl_smtp.quit(v_mailconn);
dbms_output.put_line(sqlcode||sqlerrm);
END;

Don't answer, duplicate of Re: Attach PDF using UTL_SMTP

Similar Messages

  • Sending PDF as attachment using utl_smtp

    Hi all,
    I am encountering the following problem when i try to send the email using utl_smtp builtin,i receive the mail in my outlook,but not able to read the contents of the pdf file.
    Oracle Version :- Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    source code:-
    CREATE OR REPLACE PROCEDURE "PROC_MAIL_ATTACH_PDFS" (
    p_cust_nb IN cstm.cstm_cust_nb%TYPE,
    from_name IN VARCHAR2,
    to_name IN VARCHAR2,
    subject IN VARCHAR2,
    MESSAGE IN VARCHAR2,
    p_binary_file IN VARCHAR2,
    p_seq_id IN NUMBER,
    p_ret_cd OUT NUMBER,
    p_ret_desc OUT VARCHAR2
    --ISO-8859-6
    IS
    v_smtp_server VARCHAR2 (100) := '172.20.204.17';
    --change this to your mail server
    v_smtp_server_port NUMBER := 25;
    v_directory_name VARCHAR2 (100);
    v_file_name VARCHAR2 (100);
    v_line VARCHAR2 (1000);
    crlf VARCHAR2 (2) := CHR (13)
    || CHR (10);
    mesg VARCHAR2 (32767);
    conn UTL_SMTP.connection;
    v_slash_pos NUMBER;
    v_file_handle UTL_FILE.file_type;
    invalid_path EXCEPTION;
    mesg_length_exceeded BOOLEAN := FALSE;
    l_msg VARCHAR2 (32000);
    l_tag_sep VARCHAR2 (1)
    := func_get_config_value ('TAGSEPRTR');
    l_ind VARCHAR2 (10);
    l_rec VARCHAR2 (4000);
    l_sep_rep VARCHAR2 (4000) := '17_ACCSTMT_NOV_2010';
    l_rem_rep VARCHAR2 (4000);
    l_rep VARCHAR2 (4000);
    l_mim_type VARCHAR2 (2000);
    boundary CONSTANT VARCHAR2 (256)
    := '-----DMW.Boundary.605592468';
    first_boundary CONSTANT VARCHAR2 (256) := '--' || boundary || crlf;
    last_boundary CONSTANT VARCHAR2 (256)
    := '--' || boundary || '--' || crlf;
    multipart_mime_type CONSTANT VARCHAR2 (256)
    := 'multipart/mixed; boundary="' || boundary || '"';
    mime_type VARCHAR2 (255) := 'text/html';
    l_offset NUMBER;
    l_ammount NUMBER;
    CURSOR cur_trnm
    IS
    SELECT trnm_email_enarr, trnm_email_anarr
    FROM trnm
    WHERE trnm_id = 16;
    l_enarr trnm.trnm_email_enarr%TYPE;
    l_anarr trnm.trnm_email_enarr%TYPE;
    l_message_body VARCHAR2 (32000);
    --// To check if all mails belongs to the customer already sent...
    CURSOR cur_pdfd
    IS
    SELECT COUNT (*)
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb
    AND pdfd_email_sts IS NULL
    --NEWLY ADDED ...
    AND NVL (pdfd_stmt_mode, '.') = 'E'
    AND TRUNC (pdfd_to_dt) = (SELECT MAX (TRUNC (pdfd_to_dt))
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb);
    l_cnt NUMBER := 0;
    PROCEDURE send_header (NAME IN VARCHAR2, header IN VARCHAR2)
    IS
    BEGIN
    UTL_SMTP.write_data (conn, NAME || ': ' || header || crlf);
    END;
    PROCEDURE write_raw (
    p_conn IN OUT NOCOPY UTL_SMTP.connection,
    p_message IN RAW
    IS
    BEGIN
    UTL_SMTP.write_raw_data (p_conn, p_message);
    END write_raw;
    PROCEDURE binary_attachment (
    p_conn IN OUT UTL_SMTP.connection,
    p_file_name IN VARCHAR2,
    p_mime_type IN VARCHAR2
    IS
    k_max_line_width CONSTANT PLS_INTEGER DEFAULT 54;
    v_amt BINARY_INTEGER := 672 * 3;
    /* ensures proper format; 2016 */
    v_bfile BFILE;
    v_file_len PLS_INTEGER;
    v_buf RAW (2100);
    v_buf1 RAW (2100);
    v_modulo PLS_INTEGER;
    v_pieces PLS_INTEGER;
    v_file_pos PLS_INTEGER := 1;
    v_data RAW (32767);
    v_data1 RAW (32767);
    v_chunks PLS_INTEGER;
    l_amt NUMBER := 32767;
    l_off NUMBER := 1;
    l_raw RAW (32767);
    l_raw1 RAW (32767);
    l_lob BLOB;
    l_lob_empt BLOB;
    req UTL_HTTP.req;
    resp UTL_HTTP.resp;
    resp_empt UTL_HTTP.resp;
    l_url VARCHAR2 (4000);
    l_rep_path VARCHAR2 (2000);
    l_report VARCHAR2 (100);
    l_seq_nb repq.repq_seq_nb%TYPE;
    l_parm repq.repq_parm_val%TYPE;
    l_repq repq%ROWTYPE;
    l_sts NUMBER;
    l_user VARCHAR2 (10);
    --L_MSG VARCHAR2(32000);
    l_seq_id NUMBER;
    usr_err EXCEPTION;
    --// 07-Jun-2009 - Basheer A.S. : Code added for sending A/c Statement and PFL statements in single e-mail ...
    CURSOR cur_pdfd
    IS
    SELECT
    --UTL_COMPRESS.LZ_UNCOMPRESS(PDFD_DB_FILE) PDFD_DB_FILE,
    pdfd_file_name
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb
    --AND PDFD_EMAIL_STS IS NULL
    --NEWLY ADDED ...
    --AND NVL(PDFD_STMT_MODE,'.') = 'E'
    AND pdfd_seq_nb = p_seq_id
    AND TRUNC (pdfd_to_dt) = (SELECT MAX (TRUNC (pdfd_to_dt))
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb);
    l_buffer_size INTEGER := 57;
    l_offset INTEGER := 1;
    l_raw RAW (57);
    l_file_nm pdfd.pdfd_file_name%TYPE;
    BEGIN
    --// 06-Jun-2009 - Basheer A.S. : Code added for sending A/c Statement and PFL statements in a single e-mail ...
    --// Initializing temporary CLOB data ...
    DBMS_LOB.createtemporary (l_lob, FALSE);
    --DBMS_LOB.createtemporary(L_LOB_EMPT, FALSE);
    --// Loop thro all the records for the given Customer Number...
    OPEN cur_pdfd;
    LOOP
    --FETCH CUR_PDFD INTO L_LOB, L_FILE_NM;
    FETCH cur_pdfd
    INTO --L_LOB_EMPT,
    l_file_nm;
    EXIT WHEN cur_pdfd%NOTFOUND;
    proc_audit_log ('T',
    'PROC_MAIL_ATTACH_PDFS, Customer No. '
    || p_cust_nb
    || ', File attachment: '
    || l_file_nm
    UTL_SMTP.write_data (conn, first_boundary);
    UTL_SMTP.write_data (conn,
    'Content-Transfer-Encoding: base64 '
    || UTL_TCP.crlf
    UTL_SMTP.write_data (conn,
    'Content-Type: ' || mime_type || UTL_TCP.crlf
    UTL_SMTP.write_data (conn,
    'Content-Disposition: ATTACHMENT; filename="'
    || p_file_name
    || '"'
    || UTL_TCP.crlf
    UTL_SMTP.write_data (conn, crlf);
    l_ind := '1.1';
    v_file_pos := 1;
    --// Attaching individual PDF files ...
    BEGIN
    v_modulo := 0;
    v_pieces := 0;
    v_amt := 2016;
    l_ind := '2.1';
    v_file_len := DBMS_LOB.getlength (l_lob);
    --v_file_len := dbms_lob.getlength(L_LOB_EMPT);
    v_modulo := MOD (v_file_len, v_amt);
    v_pieces := TRUNC (v_file_len / v_amt);
    IF (v_modulo <> 0)
    THEN
    v_pieces := v_pieces + 1;
    END IF;
    l_ind := '2.2';
    DBMS_LOB.READ (l_lob, v_amt, v_file_pos, v_buf);
    --dbms_lob.read(L_LOB_EMPT, v_amt, v_file_pos, v_buf);
    v_data := v_data1;
    v_chunks := 0;
    v_data := v_data1;
    FOR i IN 1 .. v_pieces
    LOOP
    v_file_pos := i * v_amt + 1;
    v_file_len := v_file_len - v_amt;
    v_data := UTL_RAW.CONCAT (v_data, v_buf);
    l_ind := '2.3';
    v_chunks := TRUNC (UTL_RAW.LENGTH (v_data) / k_max_line_width);
    IF (i <> v_pieces)
    THEN
    v_chunks := v_chunks - 1;
    END IF;
    l_ind := '2.4';
    write_raw (p_conn => p_conn,
    p_message => UTL_ENCODE.base64_encode (v_data)
    v_data := v_data1;
    IF (v_file_len < v_amt AND v_file_len > 0)
    THEN
    v_amt := v_file_len;
    END IF;
    l_ind := '2.5';
    DBMS_LOB.READ (l_lob, v_amt, v_file_pos, v_buf);
    --DBMS_LOB.READ(L_LOB_EMPT, v_amt, v_file_pos, v_buf);
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log
    ('E',
    'PROC_MAIL_ATTACH_PDFS.binary_attachment.inside BLOB loop, :'
    || SQLERRM
    || ',ind:'
    || l_ind
    END;
    v_file_pos := 1;
    UTL_SMTP.write_data (conn, UTL_TCP.crlf);
    UTL_SMTP.write_data (conn, UTL_TCP.crlf);
    END LOOP;
    --// END multiple file attachments
    l_ind := '2.6';
    UTL_SMTP.write_data (p_conn, last_boundary || UTL_TCP.crlf);
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log ('E',
    'PROC_MAIL_ATTACH_PDFS, when others:'
    || l_ind
    || ', '
    || SQLERRM
    END binary_attachment;
    BEGIN
    --// If no pending emails for the given Customer, then exit the process...
    OPEN cur_pdfd;
    FETCH cur_pdfd
    INTO l_cnt;
    CLOSE cur_pdfd;
    --// If still pending statements needs to be send...
    --IF L_CNT > 0 THEN
    IF l_cnt = 0
    THEN
    OPEN cur_trnm;
    FETCH cur_trnm
    INTO l_enarr, l_anarr;
    CLOSE cur_trnm;
    l_message_body :=
    '<html>'
    ||
    --'<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1256(Arabic)">'||
    --'<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1256">'||
    '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-6">'
    || '<body>
    <TABLE BORDER="0" WIDTH=100% style="table-layout:fixed;">
    <TR>
    <TD WIDTH="50%" ALIGN="LEFT" style="word-wrap: break-word"><B>'
    || l_enarr
    || '</B></TD>'
    || '<TD WIDTH="50%" ALIGN="RIGHT" style="word-wrap: break-word"><B>'
    || l_anarr
    || '</B></TD></TR></TABLE>
    </body>
    </html>';
    proc_audit_log ('T', 'PROC_MAIL_ATTACH_PDFS, msg:' || l_msg);
    v_smtp_server := func_get_config_value ('MAILHOST');
    v_smtp_server_port := func_get_config_value ('MAILPORT');
    l_ind := '3.1';
    conn := UTL_SMTP.open_connection (v_smtp_server, v_smtp_server_port);
    --utl_smtp.helo( conn, v_smtp_server );
    --utl_smtp.mail( conn, '[email protected]' );
    UTL_SMTP.helo (conn, v_smtp_server);
    UTL_SMTP.mail (conn, from_name);
    UTL_SMTP.rcpt (conn, to_name);
    l_ind := '3.2';
    l_rec := func_eti_tagval (l_msg, 'EMAIL');
    proc_audit_log ('T', 'PROC_MAIL_ATTACH_PDFS, l_rec:' || l_rec);
    proc_audit_log ('T', 'l_sep_rep1' || l_sep_rep);
    UTL_SMTP.open_data (conn);
    send_header ('From', '<' || from_name || '>');
    send_header ('To', '<' || to_name || '>');
    --send_header('To',''||Func_Eti_Tagval(L_MSG, 'EMAIL')||'');
    send_header ('Date', TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss'));
    send_header ('Subject', subject);
    send_header ('Content-Type', multipart_mime_type);
    UTL_SMTP.write_data (conn, first_boundary);
    --utl_smtp.write_data(conn, 'Content-Type: '||mime_type||utl_tcp.crlf);
    --utl_smtp.write_data(conn, 'Content-Type: '||mime_type||'; charset=Windows-1256'||utl_tcp.crlf);
    UTL_SMTP.write_data (conn,
    'Content-Type: '
    || mime_type
    || '; charset=ISO-8859-6'
    || UTL_TCP.crlf
    --new...
    UTL_SMTP.write_data (conn, crlf);
    UTL_SMTP.write_raw_data (conn, UTL_RAW.cast_to_raw (l_message_body));
    UTL_SMTP.write_data (conn, crlf);
    UTL_SMTP.write_data (conn, crlf);
    proc_audit_log ('T', 'l_sep_rep2' || l_sep_rep);
    binary_attachment (p_conn => conn,
    p_file_name => l_sep_rep || '.pdf',
    p_mime_type => 'multipart/mixed'
    ); --||l_sep_rep||'.pdf');
    UTL_SMTP.write_data (conn, last_boundary || UTL_TCP.crlf);
    UTL_SMTP.close_data (conn);
    UTL_SMTP.quit (conn);
    END IF;
    p_ret_cd := 0;
    p_ret_desc := 'Mail sent successfully';
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log ('E',
    'PROC_MAIL_ATTACH_PDFS, error:'
    || SQLERRM
    || 'ind:'
    || l_ind
    p_ret_cd := 1;
    END;
    Kindly help me to resolve this issue.
    Thanks & Regards
    Ariff

    pl ease check below link
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

  • Sending binary attachement using UTL_SMTP

    I am attempting to send a .PDF or Word .DOC as an attachment to an email through PL/Sql procedure. Using UTL_FILE to open the file and looping through the file using UTL_FILE.GET_RAW to extract a line then using UTL_SMTP.WRITE_RAW_DATA(conn,UTL_ENCODE.BASE64_ENCODE(<raw data>)) to write the file. I did get an email with the attachment, but when attempting to open the attachment, it cannot because it is corrupt in some way!??!
    The snippet of code is:
    l_file_handle := utl_file.fopen(l_directory_name,l_file_name,'r',32767);
    -- generate the MIME boundary line & header ...
    l_mesg := lcrlf || '--' || l_boundary_text || lcrlf ||
    'Content-Type: '|| p_mime_type|| ';' || lcrlf ||
    'Content-Disposition: attachment; filename="' ||
    l_file_name || '"' || lcrlf ||
    'Content-Transfer-Encoding: ' || p_mime_trnsf_enc || lcrlf || lcrlf;
    utl_smtp.write_data(lconn, l_mesg);
    -- and append the file contents to the end of the message ...
    BEGIN
    LOOP
    IF p_mime_trnsf_enc = '7bit' THEN
    utl_file.get_line(l_file_handle, l_line);
    l_mesg := l_line || lcrlf;
    utl_smtp.write_data(lconn, l_mesg);
    ELSE -- Base-64 encode type
    utl_file.get_raw(l_file_handle, l_line_raw, 100);
    utl_smtp.write_raw_data(lconn, utl_encode.base64_encode(l_line_raw));
    utl_smtp.write_data(lconn,lcrlf);
    END IF;
    END LOOP;
    ... followed by the UTL_FILE exceptions ...
    l_mesg := lcrlf;
    utl_smtp.write_data(lconn,l_mesg);
    utl_file.fclose(l_file_handle);
    Any suggestions???

    The documentation explicitly states:
    "With the UTL_FILE package, your PL/SQL programs can read and write operating system text files"
    See: http://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file.htm#1002119
    Also:
    "UTL_FILE.GET_RAW - This function reads a RAW string value from a file"
    See: http://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file2.htm#1003233
    I agree that this is misleading.
    You can use DBMS_LOB.LOADFROMFILE to read a file into a BLOB. You can then use DBMS_LOB.READ to read from the BLOB to a RAW.
    You can then use the RAW data to build the attachment portion of the email.

  • PDF sent using UTL_SMTP to GMail won't open. Opens in Yahoo and others

    We are using a stored procedure, in which we use UTL_SMTP to send a PDF attachment. Thing is our attachment successfully goes out. It can be opened in Yahoo, Hotmail, but we cannot open the PDF in Gmail. We get a "cannot open file" error when we click it it Gmail.
    Any help would be greatly appreciated.

    Billy, I checked the GMail mail which was not working. I forwarded it to my mail client in my PC, saved as a .eml file. I opened the file in Wordpad. This is what is there for the attachment header:
    --14dae934093fdc4a6d04b806a829--
    --14dae934093fdc4a7004b806a82b
    Content-Type: application/pdf; name="notice281.pdf"
    Content-Disposition: attachment; filename="notice281.pdf"
    Content-Transfer-Encoding: base64
    X-Attachment-Id: dfb0085649150141_0.1Then as you suggested I send a PDF from my mail-client to GMail. It opens fine in Gmail and you can also download and view it. This is what that mail has for the attachment
    pdf test
    --------------030409090802080802010404
    Content-Type: application/pdf;
    name="hdr_1999_defintions.pdf"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment;
    filename="hdr_1999_defintions.pdf"What I saw as the only difference was that in the one that is not working there is an extra line
    X-Attachment-Id: dfb0085649150141_0.1I tried to find in the code where it comes from but was not successful. I tried modifying the mailing program but still no luck.
    And also the PDF cannot be downloaded viewed as well. When we download and view the PDF we get that cannot open the pdf message.

  • I am unable to attach PDFs to Hotmail/Outlook email using my FF browser today. Never had issue before today.

    1. I am unable to attach pdfs today in Outlook/Hotmail email using my Firefox browser (27.0.1). I keep getting an error message that says, "The file is not a picture and can't be inserted inline." I do not understand why I keep getting this error message. I am not attempting to insert an image. I am selecting to Insert Files as Attachments from the drop down menu.
    No matter how many times I attempt to attach various pdfs to my emails today using Firefox as my browser, I keep getting this same error message. I have cleared the cache, cleared all cookies, cleared all history, signed out of my Hotmail/Outlook account, signed back in, restarted computer, etc., to no avail. Same problem.
    2. I switched to my Safari browser, and have no problem attaching pdfs in my Hotmail/Outlook email account. The pdfs are attaching perfectly as usual. My emails are being sent normally with the attachments. The attached pdfs are being received and are opening perfectly as intended.
    3. Why am I unable to attach files with Firefox today? Firefox is my browser of choice and I have used it with my Hotmail/Outlook email account without any problems, till today. Please help me! Thank you!

    Thank you jscher2000. Yes my PDFs do contain the .pdf extension. I tried your excellent idea to utilize the drag and drop method, but I still get the same error message with PDFs. I have no problem attaching photos or Word documents with either method; just PDFs.
    For further diagnostics, I started composing my email in Safari, attached all my pdfs and saved my email as a Draft.  I then went to Firefox, opened the draft to continue working on it, and voila!  There are all the pdfs I attached previously while in Safari.  I was able to send the email with attachments through Firefox with no issues. The attachments went through and were able to be opened.
    I am mystified, as Firefox has been trouble-free with my email account, and I have never had this particular issue till today. I made no changes to anything else on my computer, but I did notice very late last night that Outlook had one of those typical messages at the top of my Inbox to refresh my browser since Outlook had been updated. I refreshed and shut down for the night, and when I rebooted this morning that is when I discovered this brand new glitch with attachments. I'm assuming this has something to do their last update.

  • What happens to attachment in a PO when it is converted to PDF using SPOOL.

    Hi Experts,
    While converting a PO to PDF using a spool number, it works fine but i have a question as If the PO has an attachment, does the spool take care of that also?
    If not how to download the attachment as well.
    Thanks & Regards,
    K

    Hi Shan,
    No in ME21N there is a tab called Attachment, by which we can attach a note or something(I am thou not sure why this is done), yes a script is generated into a PDF but this attachment which is part of PO does it get attached or we need to do somthing to attach it to PDF was my question?
    Cheers,
    K
    Edited by: Ken Thompson on Sep 29, 2008 5:58 AM

  • How can I email using UTL_SMTP with a csv file as an attachment?

    Dear All,
    It would be great if someone could help me. I am trying to use UTL_SMTP to email with a csv file as attachment. I do get an email with a message but no attachment arrives with it.
    In fact the code used for attaching the csv file gets appended in the message body in the email.
    CREATE OR REPLACE PROCEDURE test_mail
    AS
    SENDER constant VARCHAR2(80) := '[email protected]';
    MAILHOST constant VARCHAR2(80) := 'mailhost.xxxx.ac.uk';
    mail_conn utl_smtp.connection;
    lv_rcpt VARCHAR2(80);
    lv_mesg VARCHAR2(9900);
    lv_subject VARCHAR2(80) := 'First Test Mail';
    lv_brk VARCHAR2(2) := CHR(13)||CHR(10);
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25) ;
    utl_smtp.helo(mail_conn, MAILHOST) ;
    dbms_output.put_line('Sending Email to : ' ||lv_brk||'Suhas Mitra' ) ;
    lv_mesg := 'Date: '||TO_CHAR(sysdate,'dd Mon yy hh24:mi:ss')||lv_brk||
    'From: <'||SENDER||'>'||lv_brk||
    'Subject: '||lv_subject||lv_brk||
    'To: '||'[email protected]'||lv_brk||
    'MIME-Version: 1.0'||lv_brk||
    'Content-type:text/html;charset=iso-8859-1'||lv_brk||
    ' boundary="-----SECBOUND"'||
    ''||lv_brk||
    '-------SECBOUND'||
    'Some Message'
              || lv_brk ||
    '-------SECBOUND'||
              'Content-Type: text/plain;'|| lv_brk ||
              ' name="xxxx.csv"'|| lv_brk ||
              'Content-Transfer_Encoding: 8bit'|| lv_brk ||
              'Content-Disposition: attachment;'|| lv_brk ||
              ' filename="xxxx.csv"'|| lv_brk ||
              lv_brk ||
    'CSV,file,attachement'|| lv_brk ||     -- Content of attachment
    lv_brk||
    '-------SECBOUND' ;
    dbms_output.put_line('lv_mesg : ' || lv_mesg) ;
    utl_smtp.mail(mail_conn, SENDER) ;
    lv_rcpt := '[email protected]';
    utl_smtp.rcpt(mail_conn, lv_rcpt) ;
    utl_smtp.data(mail_conn, lv_mesg) ;
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    NULL ;
    WHEN OTHERS THEN
    dbms_output.put_line('Error Code : ' || SQLCODE) ;
    dbms_output.put_line('Error Message : ' || SQLERRM) ;
    utl_smtp.quit(mail_conn) ;
    END;

    LKBrwn_DBA wrote:
    Use UTL_MAIL instead.That package is an utter disappointment - and an excellent example IMO of how not to design an application programming interface. Even the source code is shoddy.. I mean, having to resort to a GOTO statement....!!?? The person(s) who wrote that package are sorely lacking in even the most basic of programming skills if structured programming is ignored and a spaghetti command used instead.
    No wonder the public interface of that code is equally shabby and thoughtless... The mail demo code posted by Oracle was better written than this "+package+" they now have bundled as the official Mail API.
    I dunno.. if I was in product management there would have been hell to pay over pushing cr@p like that to customers.

  • When I attach PDF to an email, it uses the wrong email address

    I recently added an email account to my Outlook.  It is not the default email account, but Acrobat defaults to that address whenever I attach a PDF to an email.  Within Acrobat, the Identity under Preferences includes the correct email address.  My MS Office applications use my correct, default email address when send from them.  In Windows, the correct email is set at the default email and Outlook is my default email application.  It is only Acrobat that defaults to the wrong email account.  How can I fix this?
    I am using Acrobat 9 Standard
    I attach PDFs to email my clicking on the envelop icon.  A new message in outlook automatically opens, but the "From" field in the new email message contains the wrong email address. I have also tried File/Attach to Email with the same results.

    Hi Tricia Kritzberg,
    Tricia Kritzberg wrote:
    I recently added an email account to my Outlook.  It is not the default email account, but Acrobat defaults to that address whenever I attach a PDF to an email.  Within Acrobat, the Identity under Preferences includes the correct email address.  My MS Office applications use my correct, default email address when send from them.  In Windows, the correct email is set at the default email and Outlook is my default email application.  It is only Acrobat that defaults to the wrong email account.  How can I fix this?
    I am using Acrobat 9 Standard
    I attach PDFs to email my clicking on the envelop icon.  A new message in outlook automatically opens, but the "From" field in the new email message contains the wrong email address. I have also tried File/Attach to Email with the same results.
    You are facing this error because Outlook is your default email Client and you have configured it for different e-mail Address than the one which you intend to send mail from.
    So i would recommend you to either Add the other e-mail account( The one from which you want to send file)  in outlook so that you have a choice while sending the file.
    OR
    You can remove the currently configured e-mail account from outlook, and reconfigure outlook for that e-mail address which you want to use for file sending purpose.
    P.S.- Acrobat will always use the e-mail address associated with your Default e-mail Client ( Outlook in your case.)
    Hope that answers your question. Please revert back for any other query or assistance.
    Regards,
    Rahul Tyagi

  • Attach an xml to a pdf using ADS

    Hi all,
    I have a scenario where we are sending a Base64 encoded PDF (a bill) and the corresponding xml data from SAP backend on level 4.6C to PI 7.1. In PI we should attach the xml data to the PDF. I have already succeeded to do this using iText but we have a requirement to do this with ADS instead. In Netweaver Developer Studio I created an example project where I am reading a PDF as a byte array, also reading an XML file and try to attach the XML to the PDF using the ADS api. The project successfully built in NWDS but when I am running the project it failes.
    I am using standard code to attach the xml stream to the pdf, the error message is thrown when the following line is executed:
    IWDPDFDocument document = context.execute();
    Exception in thread "main" java.lang.ExceptionInInitializerError
         at com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.impl.PDFDocumentAccessibleContextWDImpl.execute(PDFDocumentAccessibleContextWDImpl.java:99)
         at com.eon.xi.dijnet.base64.PdfWithAttachment.addAttachmentWithSap(PdfWithAttachment.java:129)
         at com.eon.xi.dijnet.base64.PdfWithAttachment.main(PdfWithAttachment.java:218)
    Caused by: java.lang.NullPointerException
         at com.sap.tc.webdynpro.services.sal.deployment.core.DeployableObjectInternal.getSystemDeployableObjectName(DeployableObjectInternal.java:53)
         at com.sap.tc.webdynpro.clientserver.uielib.adobe.impl.AdobeFormHelper.<clinit>(AdobeFormHelper.java:115)
         ... 3 more
    Is it the problem with the PDF that it is not an Interactive Form?
    Or the problem is simply that I am trying to run the project on my local machine where ADS is not available?
    Thanks for your help.
    Pal
    Edited by: Pal Somogyi on Oct 17, 2010 10:30 PM
    Edited by: Pal Somogyi on Oct 18, 2010 11:44 AM

    Hi Pal,
    There is a requirement to generate an Adobe Form using SAP Interactive forms, and then, send this PDF to a non-SAP system using Base-64 encoding. The receiving system will decode this file and re-generate a PDF.
    I have heard that this could be done in the PI layer, using the Conversion Agent.
    Another approach which I can think of is convert PDF to binary and then use the cl_http_utility=>encode_base64 to convert binary to base64.
    You have mentioned that you have had to send a base 64 encoded pdf. Could you pelase guide me through the process?
    Thanks,
    Preethi.

  • Error in opening PDF attachment sent using SO_DOCUMENT_SEND_API1

    Hi all,
    I am converting script to PDF using FM 'SX_OBJECT_CONVERT_OTF_PDF'. Using this table i am trying to send it as a attachment to mail id. I am able to send the attachment successfully, but not able to open the attachment.
    It is giving error as 'Adobe Reader could not open file because it is either not supported file type or because the file has been damaged'.
    I tried seaching on SDN, but did not get useful answer.
    Can you please help me in resolving this error?
    Thanks,
    Archana

    Good day Archana,
    This is the same problem we have encountered, this has started after adding a patch.
    After doing so much R & D we could not do it. We have written a mail to SAP and they
    have instructed the basis consultant to follow certain procedure and finally the issue is
    solved.
    I suggest you to consult basis consultants.
    Regards and Best wishes.

  • Convert list item attachment from docx to pdf using Word Automation Services

    I have been trying to convert List Item attachments from docx to pdf using word automation services, it works in a normal document library but when I use the list attachment it throws a null reference error.
    var settings = new ConversionJobSettings();
    settings.OutputFormat = Microsoft.Office.Word.Server.Conversions.SaveFormat.PDF;
    var conversion = new ConversionJob("Word Automation Services", settings);
    conversion.UserToken = SPContext.Current.Site.UserToken;
    var wordFile = SPContext.Current.Site.RootWeb.Url + "/" + wordForm.Url;
    var pdfFile = wordFile.Replace(".docx", ".pdf");
    conversion.AddFile(wordFile, pdfFile);
    conversion.Start();
    Using reflector I was able to see my problem lies in Microsoft.Office.Word.Server.FolderIterator.cs where it uses SPFile.Item which returns NULL
    internal void CheckSingleItem(SPFile inputFile, SPFile outputFile)
    Microsoft.Office.Word.Server.Log.TraceTag(0x67337931, Microsoft.Office.Word.Server.Log.Category.ObjectModel, Microsoft.Office.Word.Server.Log.Level.Verbose, "OM: FolderIterator start a single item: source='{0}'; dest='{1}'", new object[] { inputFile.Url, outputFile.Url });
    Stopwatch stopwatch = Microsoft.Office.Word.Server.Log.StartPerfStopwatch();
    try
    this.CheckInputFile(inputFile.Item);
    this.CheckOutputFile(outputFile.Url);
    Is there any way to get around this?

    Hi Qfroth,
    According to your description, my understanding is that when you use word automation service to convert Word to PDF for list item attachment, it throws the null reference error.
    I suggest you can create an event receiver and convert the word to memory stream like below:
    private byte[] ConvertWordToPDF(SPFile spFile, SPUserToken usrToken)
    byte[] result = null;
    try
    using (Stream read = spFile.OpenBinaryStream())
    using (MemoryStream write = new MemoryStream())
    // Initialise Word Automation Service
    SyncConverter sc = new SyncConverter(WORD_AUTOMATION_SERVICE);
    sc.UserToken = usrToken;
    sc.Settings.UpdateFields = true;
    sc.Settings.OutputFormat = SaveFormat.PDF;
    // Convert to PDF
    ConversionItemInfo info = sc.Convert(read, write);
    if (info.Succeeded)
    result = write.ToArray();
    catch (Exception ex)
    // Do your error management here.
    return result;
    Here is a detailed code demo for your reference:
    Word to PDF Conversion using Word Automation Service
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Can i use HTML tag in text when sending contens as "Attachement(PDF)".

    Hi all!!
    i try to add html tag on ibot email text column.
    is it possible?
    - in ibot delivery content.
    send content as Attachment(PDF)
    "if sent as attachement, include this text" <--- mark this field
    and below multi line input column, can i use html tag, for example,
    Yahoo
    thanks in advance.
    Edited by: vingorius on 2010. 10. 31 오후 7:27

    hi vingorius ,
    No you cant include html but u can use variables
    To add a variable in a text message to provide context for the iBot attachment
    1. Click the following option:
    If sent as attachment, include this text
    2. Type the text into the text box with a session variable, a repository variable, or a presentation variable using the syntax shown in the following table:
    Variable Type
    Syntax
    Repository @{Variable_Name}
    Session @{NQ_SESSION.Variable_Name}
    Presentation @{Variable_Name}
    For example, Dear, @{NQ_SESSION.Variable_Name}, here is your personalized Weekly Sales Territory Update.
    NOTE: If you want to use the @ character, you need to precede it with the \ (back slash) character to separate it from the variable syntax. For example, Dear @{NQ_SESSION.DISPLAYNAME}, \@ New York, appears as Dear Joe Smith, @ New York.
    Source : BI Guide
    Thanks,
    Saichand.v

  • Random new line issue in email attachment using utl_smtp need your help.

    Hi
    I am getting one problem unable to solve, need your help.
    I am creating one csv attachment in email using utl_smtp.
    but there are random newline in the attachment value so the csv getting corrupted.
    following is the attachment code
    FOR C2 IN CUR_VALIDATION_ERROR
                 LOOP
                   IF CUR_VALIDATION_ERROR%ROWCOUNT = 1 THEN
                     UTL_SMTP.write_data(l_mail_conn,'"LOG DATE","DATA ERROR IDENTIFIER","EMPLOYEE ID","SOURCE SYSTEM","SOURCE FILE ROW","ERROR LEVEL","ERROR MESSAGE"'||CHR(13));
                   END IF; 
                   UTL_SMTP.write_data(l_mail_conn,
                                                     chr(34)||C2.LOG_DT||chr(34)||chr(44)||
                                                     chr(34)||C2.DATA_ERR_ID||chr(34)||chr(44)||
                                                     chr(34)||C2.EMPE_ID||chr(34)||chr(44)||
                                                     chr(34)||C2.SOURCE||chr(34)||chr(44)||
                                                     chr(34)||C2.SOURCE_ROW||chr(34)||chr(44)||
                                                     chr(34)||C2.ERROR_LEVEL||chr(34)||chr(44)||
                                                     chr(34)||C2.ERR_MSG_DSCR||chr(34)||
                                                     CHR(13));
                 END LOOP;

    Thank you hm, but that is not the case, bcz I found newline character inside a sequence number. Its not possible to have newline character inside a sequence number
    "LOG DATE","DATA ERROR IDENTIFIER","EMPLOYEE ID","SOURCE SYSTEM","SOURCE FILE ROW","ERROR LEVEL","ERROR MESSAGE"
    "02-MAY-2012","7893660","123","XYZ","44952","WARNING","[02-MAY-12] - The value in field [PHONE]"
    "02-MAY-2012","7893663","12
    4","XYZ","52382","WARNING","[02-MAY-12] - The value in field [ADDRESS]"

  • Sending text Attachment using UTL_SMTP

    Hi,
    I am using UTL_SMTP package for sending a text file thru' a mail.
    Our database is in a unix machine. My file is created in a folder oracle/DEV/CCare/Data which is in the root directory.
    In the URL argument of the procedure,which is a varchar2 type, i am passing the path as 'oracle/DEV/CCare/Data'. Also i have tried passing '/oracle/DEV/CCare/Data' like this. But none of them is working could anybody suggest way of passing the URL.
    The package arguments look like below.
    oks_mail.send_attachment(sender => l_fromemailid,
    recipient_tbl => to_mail_tbl,
    subject => 'Progress report for CCC Feed',
    mail_text => l_mailtext1,
    url => '//10.10.81.3/oracle/DEV/CCare/Data',
    file_name => filename);

    Use
    FILE_ARRAY(1) := file_name;
    RETURN_DESC1 := '10 - E: THERE WAS AN ERROR IN OPENING CONNECTION. ';
    CONN:= UTL_SMTP.OPEN_CONNECTION( L_SMTP_SERVER, L_SMTP_SERVER_PORT ); /** OPEN CONNECTION ON THE SERVER **/
    UTL_SMTP.HELO( CONN, L_SMTP_SERVER ); /** DO THE INITIAL HAND SHAKE **/
    UTL_SMTP.MAIL( CONN, L_SENDER_NAME );
    RETURN_DESC1 := '20 - E: THERE WAS AN ERROR IN CREATING RECEIPIENTS. ';
    UTL_SMTP.RCPT( CONN, '[email protected]');
    UTL_SMTP.OPEN_DATA ( CONN );
    --Send_header('Subject', 'File - ');
    /*** GENERATE THE MIME HEADER ***/
    RETURN_DESC1 := '30 - E: THERE WAS AN ERROR IN GENERATING MIME HEADER. ';
    L_MESG:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' )|| CRLF ||
    'From: ' || L_SENDER_NAME || CRLF ||
    'Subject: ' || file_name || CRLF ||
    'To: ' || L_MSG_TO || CRLF ||
    'Mime-Version: 1.0' || CRLF ||
    'Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"'|| CRLF ||
    '' || CRLF ||
    'This is a Mime message, which your current mail reader may not' || CRLF ||
    'understand. Parts of the message will appear as text. If the remainder' || CRLF ||
    'appears as random characters in the message body, instead of as' || CRLF ||
    'attachments, then you''ll have to extract these parts and decode them' || CRLF ||
    'manually.' || CRLF ||'' ;/*|| CRLF ||
    '--DMW.Boundary.605592468' || CRLF ||
    'Content-Type: text/plain; name="message.txt"; charset=US-ASCII' || CRLF ||
    'Content-Disposition: inline; filename="message.txt"' || CRLF ||
    'Content-Transfer-Encoding: 7bit' || CRLF ||
    '' || CRLF || CRLF || CRLF || CRLF ;*/
    L_MESG_LEN := LENGTH(L_MESG);
    IF L_MESG_LEN > MAX_SIZE THEN
    MESG_LENGTH_EXCEEDED := TRUE;
    END IF;
    RETURN_DESC1 := '40 - E: THERE WAS AN ERROR IN WRITING MESSAGE TO CONNECTION. ';
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    /*** START ATTACHING THE FILES ***/
    FOR I IN 1..1 LOOP
    EXIT WHEN MESG_LENGTH_EXCEEDED;
    IF FILE_ARRAY(I) IS NOT NULL THEN
    BEGIN
    L_SLASH_POS := INSTR(FILE_ARRAY(I), '/', -1 );
    IF L_SLASH_POS = 0 THEN
    L_SLASH_POS := INSTR(FILE_ARRAY(I), '\', -1 );
    END IF;
    L_DIRECTORY_NAME := SUBSTR(FILE_ARRAY(I), 1, L_SLASH_POS - 1 );
    L_FILE_NAME := SUBSTR(FILE_ARRAY(I), L_SLASH_POS + 1 );
    RETURN_DESC1 := '50 - E: THERE WAS AN ERROR IN OPENING FILE. ';
    L_FILE_HANDLE := UTL_FILE.FOPEN(L_DIRECTORY_NAME, L_FILE_NAME, 'R' );
    L_MESG := CRLF || '--DMW.Boundary.605592468' || CRLF ||
    'Content-Type: application/octet-stream; name="' || L_FILE_NAME || '"' || CRLF ||
    'Content-Disposition: attachment; filename="' || L_FILE_NAME || '"' || CRLF ||
    'Content-Transfer-Encoding: 7bit' || CRLF || CRLF ;
    L_MESG_LEN := L_MESG_LEN + LENGTH(L_MESG);
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    LOOP
    RETURN_DESC1 := '60 - E: THERE WAS AN ERROR IN READING FILE. ';
    UTL_FILE.GET_LINE(L_FILE_HANDLE, L_LINE);
    IF L_MESG_LEN + LENGTH(L_LINE) > MAX_SIZE THEN
    L_MESG := '*** truncated ***' || CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    MESG_LENGTH_EXCEEDED := TRUE;
    EXIT;
    END IF;
    L_MESG := L_LINE || CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    L_MESG_LEN := L_MESG_LEN + LENGTH(L_MESG);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    out_errcode:=-500;
    WHEN UTL_FILE.INVALID_PATH THEN
                        RAISE ABORT_PROGRAM;
    WHEN OTHERS THEN
    RAISE ABORT_PROGRAM;
    END;
    L_MESG := CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    UTL_FILE.FCLOSE(L_FILE_HANDLE);
    END IF;
    END LOOP;
    RETURN_DESC1 := '70 - E: THERE WAS AN ERROR IN CLOSING MIME BOUNDARY. ';
    L_MESG := CRLF || '--DMW.Boundary.605592468--' || CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    UTL_SMTP.CLOSE_DATA( CONN );
    UTL_SMTP.QUIT( CONN );

  • How To Open PDF Attached file use CLIENT_HOST 11 g forms

    How to open pdf file on client side at 11 g forms ?
    when i open any attached (PDF )file on client side is not open those file open on server side plz guide me how to  open those file on client machine using client host?
    thanks

    Where is the pdf you are trying to open? Is it on the server or the client? If the file is stored on the server then you can access it using WEB.SHOW_DOCUMENT assuming it is stored in a place that has a virtual mapping. For example:
    WEB.SHOW_DOCUMENT ('http://server/someLocation/file.pdf','_blank');If the file is on the client then you need to configure your application to use WebUtil. Then you can do what Francois suggested.

Maybe you are looking for

  • Look and Feel

    Salutations, I am writing a simple swing program that when the user clicks a button corresponding to a look and feel name ie "Metal" etc. the Look and Feel is Changed, it works great except for one problem, it will not change to the "Metal" look and

  • Transform an object draft (purchase invoice) to one final with SDK.

    Some body help me.           I need transform an object draft (purchase invoice) to one final with SDK.   I want make a massive approving puchase invoice in draf mode. How can i do that??? CGM

  • Detecting Loaded Flash Chart

    I have a page with a report region and a flash chart. I created a printer friendly template for this and in it included some script to print the page using the onload event. The problem is that when the print dialog box comes up the chart is sometime

  • I can´t install itunes in my laptop

    i have it before, and it used to worked really good. i don´t know what happened..it started giving me an error, and finally stop working. Now i can´t install it any more. (i have win xp) Please, I need help

  • Using PSE13 with Epson Perfection V600 Scanner

    I own an Epson Perfection V600 scanner and have always preferred the TWAIN driver (see TWAIN not installed | Photoshop Elements 9 and later) over WIA. Since installing PSE13 64 Bit I no longer have Adobe's TWAIN driver. I recommend using Epson's late