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.

Similar Messages

  • 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 );

  • 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

  • Regarding sending .PDF attachment through utl_smtp package

    Hi All,
    How can i send .PDF attachment throuch UTL_SMTP package using oacle pl/sql.
    Regds
    Shailesh

    http://www.google.com/search?q=UTL_SMTP+attachment
    results in a lot of hits how to do this; e.g.: http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
    If you are having trouble with the above samples feel free to ask and don't forget to include as much information as possible (e.g. 4 digit database and forms version, your sample source code etc.).
    cheers

  • Send excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi ABAPers,
    I managed to send excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1.
    Let say I send it to my own email account.
    But, when try to open the excel document, from lotus notes, there is warning message produced by the microsoft excel saying:
    "The file is not in a recognizable format.
    and so on....."
    Anyway, when I click button 'OK', excel sheet will be opened and no information lost.
    How can we code the abap program so that the message will not come each time I open the attachment from my lotus notes?
    Or this is just the tab delimited issue?
    Thank you.
    Regards,
    Edward.

    Hi Shan,
    Thank you for replying.
    I have the same as follows:
      DESCRIBE TABLE lt_contents_hex LINES lv_lines.
      lt_packing_list-transf_bin = 'X'.
      lt_packing_list-head_start = 1.
      lt_packing_list-head_num   = 1.
      lt_packing_list-body_start = 1.
      lt_packing_list-body_num   = lv_lines.
      lt_packing_list-doc_type   = 'XLS'.
      lt_packing_list-obj_name   = 'ATTACHMENT'.
      lt_packing_list-obj_descr  = 'Attachment'.
      lt_packing_list-doc_size   = lv_lines * 255.
      APPEND lt_packing_list.
    I'm using lt_contents_hex instead of lt_contents_bin.
    Still the problem is there.
    Is there any other way to calculate the doc size correctly?
    Regards,
    Edward.

  • Sending e-mail using utl_smtp on oracle 9i

    Hello
    I have problem with sending e-mails using utl_smtp package.
    My code looks like this:
    lv_mail_conn := utl_smtp.open_connection(lv_mailhost_txt);
    utl_smtp.ehlo(lv_mail_conn, lv_mailhost_txt);
    res :=     utl_smtp.command(lv_mail_conn, 'AUTH LOGIN');
    res := utl_smtp.command(lv_mail_conn, <login in base64>);
    res := utl_smtp.command(lv_mail_conn, <password in base64>);
    And I get en error after sending a password to SMTP server.
    Error code: 535, text: 5.7.3 Authentication unsuccessful.
    This happens on oracle 9i.
    I have another server for testing which has oracle 10g installed. This code works fine on oracle 10g but doesn't work on oracle 9i.
    Do you have any ideas what's wrong? I assume that SMTP server (microsoft exchange) work correctlys because I can send e-mail from test server.

    Ok problem solved :)
    Problem was between oracle and MS exchange server. Live server oracle 9i is on linux, and testing server works on windows.
    So the problem was with configuration. Our admins corrected it and now works :). I don't know details.

  • When I send an attachment using Word for MAC people have a hard time opening it with a PC. Can I do anything different?MAC

    When I try to send an attachment using Word for MAC people have a hard time opening it with a PC. Can I do anything different?

    shldr2thewheel already sent a teach-yourself way. Perhaps you could be more specific: any .doc file written in Mac OS is opened with difficulty? what version of Office on mac and what version in windows? any format, e.g. .doc or .rtf? Even a simple rtext of, say, 2-3 pages? or only long docs, e.g. 100 pages or more? what language is used? English or any other West European, Latin based text, or other scripts too? What do you understand by ‘people have a hard time opening it with a PC?’ takes a very long time? or does not open at all? etc. etc.

  • How to format and send html email using utl_smtp

    Hi,
    I need to send email in the html format from within the database using utl_smtp. I am really not interested in creating os level file using "set markup html on spool on" and sending that as an html attachment. Can someone please give a code?
    1. Output of a select needs to be emailed (for example : select empid, name from emp, salary)
    2. Certian cells for example salary < 4800 needs to be higlighted in Red color
    3. I need to send email which is having more than 32767 characters (I can not use varchar2 field)
    I have reffered to following url on asktom:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1739411218448
    However it does not help.
    If someone has a sample code with any select from a table, it would be a great help.
    Regards
    Sudhanshu Bhandari

    There have been many very good threads on sending email using the UTL_SMTP on the forum including threads that deal with HTML formated mail.
    The basic process is to the same as with sending regular (non HTML) mail, but you add some additional headers to the mail message as well as additional formatting to the message body (e.g. HTML tags as needed).
    Specifically you need to add the two following headers:
    MIME-Version: 1.0
    Content-type: text/html

  • 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 mail from using utl_smtp error......

    Hi
    When i try to send mail like as follows
    DECLARE
    v_connection UTL_SMTP.CONNECTION;
    BEGIN
    v_connection := UTL_SMTP.OPEN_CONNECTION('xxx.xxx.xxx.xxx',25);
    UTL_SMTP.HELO(v_connection,'xxx.xxx.xxx.xxx');
    UTL_SMTP.MAIL(v_connection,'[email protected]');
    UTL_SMTP.RCPT(v_connection,'[email protected]');
    UTL_SMTP.DATA(v_connection,'Sent From PL/SQL');
    UTL_SMTP.QUIT(v_connection);
    END;
    I get the following error..
    ERROR at line 1:
    ORA-29278: SMTP transient error: 421 Service not available
    ORA-06512: at "SYS.UTL_SMTP", line 17
    ORA-06512: at "SYS.UTL_SMTP", line 96
    ORA-06512: at "SYS.UTL_SMTP", line 138
    ORA-06512: at line 4
    if i send mail from outlook it goes...the configuration is like this
    in mail properties general tab
    email address : [email protected]
    and i have to tick mark the "include this account when receiving mail or synchro" option
    in servers tab
    POP3 : xxx.xxx.xxx.xxx
    smtp : xxx.xxx.xxx.xxx
    and i have to tick the "My server requires authentication" option
    and have to give the setting for that also
    ie. log on using account : [email protected]
         password: xxxxxx
    How to Correct it ?
    Kris

    i am on the same platform and in same account..... and PL/SQL UTL_SMTP gets a connection plus SMTP error, while telnet cannot even get a connection. A very weird one. Not sure what the problem can be.
    Worse case, forget telnet and do all your troubleshooting using UTL_SMTP.. with liberal usage of DBMS_OUTPUT. :-)
    regd. the connection from my xp client it is
    connecting to the telnet server on server, but when i
    tri to connect to the ISP's smtp address it throws
    the errorNot that strange. You're likely going through a proxy of sorts of to reach the ISP mail server. Besides, to send mail you should be able to use your company's SMTP server as it should route Internet e-mail out to the net automatically.
    In fact, many SMTP servers will not allow you to relay via them. E.g. if you connect from domain 1 to SMTP server on domain 2, and you submit an e-mail to be delivered to domain 3, the domain 2 server will tell you to take a hike. It will only accept mail that is destined for its own domain or originating from its own domain.
    Reason for this is spam. Open relays are one of the prime reasons for having billions of spam mails being transmitted.
    The correct method will be for you on domain 1 to connect to domain 1's SMTP server and submit an e-mail to be delivered to domain 3. That will be accepted and delivered. Using domain 2 as an intermediate agent to act as a relay, is/should not be accepted by all SMTP servers. (your SMTP server should get blacklisted/blackholed if it has an open relay)

  • Sending Binary data using ASCII

    Hello All,
    I'm trying to control serial-interface instrument using NI-VISA with a set of ASCII codes, but the instrument reads/sends binary data only. What should I do so that the ASCII codes I send are converted into binary commands for the instrument to read, and that the data I receive is converted back into ASCII?
    Thanks in advance
    M

    Hi M,
    first you should define the words "binary commands/data". Then you should know: ASCII is binary too...
    You may work with an U8 array. You can easily convert strings to U8 arrays and vice-versa!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Sending Binary Data using HTP package

    Has anyone been successful in using the HTP package and its PUTRAW procedure to send binary data to a browser?
    Example code shows basic idea:
    create or replace
    procedure test_raw as
    output VARCHAR2(20);
    begin
    OWA_UTIL.MIME_HEADER('application/x-gzip', TRUE);
    output := 'Hello World!';
    HTP.PUTRAW(UTL_RAW.CAST_TO_RAW(output));
    HTP.FLUSH;
    end test_raw;
    I receive an empty file when called from the browser.
    What gives?

    I found my answer. I should be using wpg_docload.download_file(BLOB) to "download" a the contents of a BLOB.

  • Sending email attachements using unix !!

    hi
    I want to send report generated my spooled file as attachment using unix shell script.
    Can somebody help me out ?
    many thanks

    Nothing to do with PL/SQL.
    Anyway, here's a snippet from a Unix shell script I wrote that does notification (via various methods). The code snippet is from the part where an e-mail with attachment is created for the Unix mail command. The variable names are (I hope) self explanatory.
    <font color="blue">
    ConstructMail()
      # do we have an attachment and does the file exist?
      if  [ "$ATTACHMENT" != "" ] && [ ! -f $ATTACHMENT ]
      then
        Abort "Error. File [$ATTACHMENT] not found."
      fi
      # create the boundary tags for the attachment
      if [ "$ATTACHMENT" != "" ]
      then
        BASE=`basename ${ATTACHMENT}`
        BOUNDS1="-"`hostname`.`date +%y%m%d%H%M`.$$
        BOUNDS2="--"$BOUNDS1
      fi
      # now we construct a MIME e-mail that includes boundaries for e-mail
      # attachments
      echo "To: $EMAIL_RECIPIENT"                              >> $LETTER
      echo "Subject: $SUBJECT"                                    >> $LETTER
      echo "MIME-Version: 1.0"                                    >> $LETTER
      if  [ "$ATTACHMENT" = "" ]
      then
        echo "Content-Type: Text/plain; charset=US-ASCII"           >> $LETTER
      else
        echo "Content-Type: Multipart/Mixed; Boundary=\"$BOUNDS1\"" >> $LETTER
        echo ""                                                     >> $LETTER
        echo "$BOUNDS2"                                             >> $LETTER
        echo "Content-Type: Text/plain; charset=US-ASCII"           >> $LETTER
      fi
      # now let's add the message's text body
      if [ -f $LETTER_BODY ]
      then
        cat $LETTER_BODY                                            >> $LETTER
      else
        Abort "Error. Letter body [$LETTER_BODY] not found!"
      fi
      # if we have an attachment, let's add it now
      if  [ "$ATTACHMENT" != "" ]
      then
        echo "$BOUNDS2"                                                   >> $LETTER
        echo "Content-Type: Text/plain; charset=US-ASCII; name=\"$BASE\"" >> $LETTER
        cat ${ATTACHMENT}                                                 >> $LETTER
      fi
    </font>The only real complexity is creating the boundary tags between attachment and the mail body - and of course specifying the correct e-mail headers so that the mail reader will know what is what.
    The above code creates a $LETTER file and this is then simply e-mailed using the Unix mail command, e.g.
    /usr/bin/mail $RECIPIENT < $LETTER
    More details in RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. http://www.faqs.org/rfcs/rfc2045.html

  • Send binary file using xml

    Hi all,
    I've got an application wich currently sends xml messages through sockets between server and client. Now, I'd like to be able of sending binary files (jpegs and other images...) as some content of these files. Is it possible with CDATA? Do you know any URL with an example or something?
    thanks a lot!

    This is a little example that shows the solution I adopted.
    Two classes, a server and a client, execute the server in a given port and the client with "localhost" as ip and the same port as the server.
    Ex: java Server 5555
    java Client localhost 5555
    the code:
    import java.net.*;
    import java.io.*;
    public class Server {
        public static void main(String[] args) {
            ServerSocket serverSocket = null;
            if(args.length!=1){
                System.out.println("ERROR: java Server <port>");
            } else {
                   // Create listening socket
                   try {
                        serverSocket = new ServerSocket((new Integer(args[0])).intValue());
                   } catch (IOException e) {
                        System.out.println("ERROR: not possible to listen on the specified port");
                        System.exit(1);
                   // Create wait for connection
                   Socket clientSocket = null;
                   try {
                        clientSocket = serverSocket.accept();
                   } catch (IOException e) {
                        System.err.println("ERROR: Accept failed.");
                        System.exit(1);
                   try{
                          // Get the output channel
                        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
                        // Send a xml message
                        out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?><FOO><VAR message=\"ugly harcoded XMLmessage\"/></FOO>\0");
                        out.flush();
                        out.close();
                        clientSocket.close();
                        serverSocket.close();
                   } catch(IOException IOE){
                        System.out.println("ERROR: on send");
    import java.io.*;
    import org.w3c.dom.Document;
    import java.net.*;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.xml.sax.SAXException;
    import org.xml.sax.InputSource;
    public class Client {
         public static void handleIncomingMessage(Document doc){
            System.out.println("DO WHAT YOU WANT WITH THE XML!");
        public static void main(String[] args){
            BufferedReader in = null;
            Socket socket = null;
            if(args.length!=2){
                System.out.println("ERROR: java Client <ip> <port>");
            } else {
                String ip = args[0];
                int port = (new Integer(args[1])).intValue();
                   // Open a socket to the server
                try {
                        socket = new Socket(ip,port);
                   } catch (UnknownHostException e) {
                        System.out.println("ERROR: Unknow host!");
                        System.exit(1);
                   } catch (IOException e) {
                        System.out.println("ERROR: I/O error");
                        System.exit(1);
              try {
                // Get the input channel
                   in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            } catch (IOException e) {
                System.err.println("ERROR: I/O error");
                System.exit(1);
              // Create a DocumentBuilder to convert the socket's incoming String
            // to a XML parsed Document
              Document XMLmessage =null;
            DocumentBuilder builder = null;
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              try{
                   builder = factory.newDocumentBuilder();
            } catch (ParserConfigurationException PCE) {
                System.out.println(PCE.toString());
              try{
                String messageRead = "";
                char caracter;
                StringBuffer sb = null;
                   // Read from the socket until \0
                   sb = new StringBuffer();
                   caracter =(char)in.read();
                   while(caracter != '\0'){
                        sb.append(caracter);
                        caracter = (char)in.read();
                   messageRead = sb.toString();
                   System.out.println("Recieved: "+messageRead);
                // Parse the read message
                   try{
                        XMLmessage = builder.parse(new InputSource((Reader)new StringReader(messageRead)));
                        // Work with it
                        handleIncomingMessage(XMLmessage);
                   } catch(IOException IOE){
                        System.out.println(IOE.toString());
                   } catch(SAXException SE) {
                        System.out.println(SE.toString());
              } catch(IOException IOE){
                   System.out.println("ERROR: I/O error");
    }hope it helps!
    any comment about the code will be welcome

  • Is there any possibilit​y to send binary messages using the TCPIP write?

    It seems that TCPIP write only accepts strings as input. I need to send binary messages. How can I manage that?
    Thanks,
    Hélène.

    Helene wrote:
    > It seems that TCPIP write only accepts strings as input. I need to
    > send binary messages. How can I manage that?
    >
    With a type-cast (in the "Advanced" submenu) you can easyly convert
    Binary-Data to a string.Than you can send it over TCP/IP and convert it
    back at the other end.
    Maybe this helps a bit.
    bye
    Marco

Maybe you are looking for