Attaching files in a mail using utl_smtp package

I am using a batch file to automate
execution of a sql script. The script would generate a .csv file and I now need to mail this file to a user at regular intervals.
Please suggest a good tool to attach the file and send a mail. I tried utl_smtp package, but its not possible to attach a file and also, the text size should not be more than 1000 characters.
Thank you,

http://www.softtreetech.com/
has a package DB mail.
Check this out.

Similar Messages

  • Mail using utl_smtp package

    can we send attachment with mail by using utl_smtp package.
    i am using form6i with database 9i in 2 tier environment

    Hi,
    read the following:
    Can 9i email utl_smtp send attachments? ,
    Re: sending attchements with utl_smtp
    As an alternative there is also the UTL_MAIL built-in package as well...
    Regards,
    Simon

  • 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.

  • I used to have a indicator of time when attaching file in Yahoo Mail...I no longer have that in Safari 5.1.5...How can I get that indicator back???

    I used to have a indicator of time when attaching file in Yahoo Mail...I no longer have that in Safari 5.1.5...How can I get that indicator back???

    I tried to find help with the support by web chat for 2 days already, but every time it says that chat is un available (even if it's suppose to be 24/7)... I dont know what else to do.... please help!

  • The old attaching file to e-mails chestnut

    Hi Folks.
    Here's the deal. On my own independant Oracle 9i DB running on my machine I am able to generate and send an e-mail using UTL_SMTP. I am able to attach a file to it as well!! No problems at all.
    However..
    The 'Live' DB is running on the server and it is an 8i DB.
    I have run the relevant initjvm code, set the UTL_FILE_DIR to * (Just for development) and I have setup the SMTP service.
    The problem I have is that when I run my Forms module and attempt to send the e-mail in a Client-Server setup the e-mail is generated, the to, from, subject and message elements are all there but no matter what I seem to try the specified file on the 'client' machine is not getting attached. I have tried setting the UTL_FILE_DIR to the full Windows path of the file I want to attach and still no joy.
    Does anyone have any suggestions?
    Many thanks
    Simon

    don't think it is possible on 8i to send an email with attachment (using utl_smtp).
    You could use the javamail api provided for free by sun.
    you can find more information on http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:255615160805
    greetings
    Freek D
    Hi Folks.
    Here's the deal. On my own independant Oracle 9i DB running on my machine I am able to generate and send an e-mail using UTL_SMTP. I am able to attach a file to it as well!! No problems at all.
    However..
    The 'Live' DB is running on the server and it is an 8i DB.
    I have run the relevant initjvm code, set the UTL_FILE_DIR to * (Just for development) and I have setup the SMTP service.
    The problem I have is that when I run my Forms module and attempt to send the e-mail in a Client-Server setup the e-mail is generated, the to, from, subject and message elements are all there but no matter what I seem to try the specified file on the 'client' machine is not getting attached. I have tried setting the UTL_FILE_DIR to the full Windows path of the file I want to attach and still no joy.
    Does anyone have any suggestions?
    Many thanks
    Simon

  • How can i use UTL_SMTP package in oracle 8i 1.5

    i want to use UTL_SMTP package to send mail but i have installed oracle 8i 1.5
    i know that UTL_SMTP package come with oracle 8i 1.6
    i will send mail from eudora
    thanks

    Hi,
    Run d:/oracle/ora81/rdbms/admin/utlsmtp.sql as SYS user. It create the package UTL_SMTP.
    Hope this helps.
    rukmini

  • Send mail using utl_smtp

    Hi Experts,
    I am using utl_smtp package to send a mail from oracle procedure. My procedure is
    CREATE OR REPLACE PROCEDURE TEST_UTLFILE_EMAIL (pSender VARCHAR2, pRecipient VARCHAR2, pSubject VARCHAR2, pMessage VARCHAR2) IS
    mailhost CONSTANT VARCHAR2(30) := 'host';
    crlf CONSTANT VARCHAR2(2):= CHR(13) || CHR(10);
    mesg VARCHAR2(1000);
    mail_conn utl_smtp.connection;
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    mesg := 'Date: ' ||
    TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss') || crlf ||
    'From: <'|| pSender ||'>' || crlf ||
    'Subject: '|| pSubject || crlf ||
    'To: '||pRecipient || crlf || '' || crlf || pMessage;
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, pSender);
    utl_smtp.rcpt(mail_conn, pRecipient);
    utl_smtp.data(mail_conn, mesg);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN INVALID_OPERATION THEN
    NULL;
    WHEN TRANSIENT_ERROR THEN
    NULL;
    WHEN PERMANENT_ERROR THEN
    NULL;
    WHEN OTHERS THEN
    NULL;
    END TEST_UTLFILE_EMAIL;
    when i compiled this procedure, this is giving following error message.
    LINE/COL ERROR
    0/0 PL/SQL: Compilation unit analysis terminated
    19/8 PLS-00201: identifier 'INVALID_OPERATION' must be declared
    Please help me out in solving this.
    Regards,
    Chandu

    Define the exception's like
    CREATE OR REPLACE PROCEDURE TEST_UTLFILE_EMAIL(pSender VARCHAR2,
    pRecipient VARCHAR2,
    pSubject VARCHAR2,
    pMessage VARCHAR2) IS
    mailhost CONSTANT VARCHAR2(30) := 'host';
    crlf CONSTANT VARCHAR2(2) := CHR(13) || CHR(10);
    mesg VARCHAR2(1000);
    mail_conn utl_smtp.connection;
    invalid_operation EXCEPTION; -- Operation is invalid
    transient_error EXCEPTION; -- Transient server error in 400 range
    permanent_error EXCEPTION; -- Permanent server error in 500 range
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    mesg := 'Date: ' || TO_CHAR(SYSDATE, 'dd Mon yy hh24:mi:ss') || crlf ||
    'From: <' || pSender || '>' || crlf || 'Subject: ' ||
    pSubject || crlf || 'To: ' || pRecipient || crlf || '' || crlf ||
    pMessage;
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, pSender);
    utl_smtp.rcpt(mail_conn, pRecipient);
    utl_smtp.data(mail_conn, mesg);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN INVALID_OPERATION THEN
    NULL;
    WHEN TRANSIENT_ERROR THEN
    NULL;
    WHEN PERMANENT_ERROR THEN
    NULL;
    WHEN OTHERS THEN
    NULL;
    END TEST_UTLFILE_EMAIL;

  • Attaching File While Sending Mail

    Dear All,
                I want to send mail through sap for that i have used function module 'SO_NEW_DOCUMENT_SEND_API1'. Can anybode tell me how can i attach file in this mail.
    Regards,
    Mayank

    hi check this..
    REPORT  ZMAIL.
    TABLES: ekko.
    PARAMETERS: p_email   TYPE somlreci1-receiver .(give email here)
    TYPES: BEGIN OF t_ekpo,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
    END OF t_ekpo.
    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
          wa_ekpo TYPE t_ekpo.
    TYPES: BEGIN OF t_charekpo,
      ebeln(10) TYPE c,
      ebelp(5)  TYPE c,
      aedat(8)  TYPE c,
      matnr(18) TYPE c,
    END OF t_charekpo.
    DATA: wa_charekpo TYPE t_charekpo.
    DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
            t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
            t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            w_cnt TYPE i,
            w_sent_all(1) TYPE c,
            w_doc_data LIKE sodocchgi1,
            gd_error    TYPE sy-subrc,
            gd_reciever TYPE sy-subrc.
    *START_OF_SELECTION
    START-OF-SELECTION.
      Retrieve sample data from table ekpo
      PERFORM data_retrieval.
      Populate table with detaisl to be entered into .xls file
      PERFORM build_xls_data_table.
    *END-OF-SELECTION
    END-OF-SELECTION.
    Populate message body text
      perform populate_email_message_body.
    Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_message
                                          it_attach
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'XLS'
                                          'filename'
                                 changing gd_error
                                          gd_reciever.
      Instructs mail send program for SAPCONNECT to send email(rsconn01)
      PERFORM initiate_mail_execute_program.
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT ebeln ebelp aedat matnr
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekpo.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  BUILD_XLS_DATA_TABLE
          Build data table for .xls document
    FORM build_xls_data_table.
      data: ld_store(50) type c.  "Leading zeros
      CONSTANTS: con_cret(5) TYPE c VALUE '0D',  "OK for non Unicode
                 con_tab(5) TYPE c VALUE '09'.   "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    *constants:
       con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
       con_cret type c value cl_abap_char_utilities=>CR_LF.
      CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR' INTO it_attach SEPARATED BY con_tab.
      CONCATENATE con_cret it_attach  INTO it_attach.
      APPEND  it_attach.
      LOOP AT it_ekpo INTO wa_charekpo.
    *Modification to retain leading zeros
      inserts code for excell REPLACE command into ld_store
      =REPLACE("00100",1,5,"00100")
        concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'
                                 wa_charekpo-ebelp '")' into ld_store .
      concatenate ld_store into .xls file instead of actual value(ebelp)
        CONCATENATE wa_charekpo-ebeln ld_store  wa_charekpo-aedat wa_charekpo-matnr  INTO it_attach SEPARATED BY con_tab.
        CONCATENATE con_cret it_attach  INTO it_attach.
        APPEND  it_attach.
      ENDLOOP.
    ENDFORM.                    " BUILD_XLS_DATA_TABLE
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM send_file_as_email_attachment tables pit_message
                                              pit_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = pit_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
          Instructs mail send program for SAPCONNECT to send email.
    FORM initiate_mail_execute_program.
      WAIT UP TO 2 SECONDS.
      SUBMIT rsconn01 WITH mode = 'INT'
                    WITH output = 'X'
                    AND RETURN.
    ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
    *&      Form  POPULATE_EMAIL_MESSAGE_BODY
           Populate message body text
    form populate_email_message_body.
      REFRESH it_message.
      it_message = 'Please find attached a list test ekpo records'.
      APPEND it_message.
    endform.                    " POPULATE_EMAIL_MESSAGE_BODY
    regards,
    venkat

  • Safari 5.0 freezes after attaching files in Yahoo Mail

    Since upgrading to Safari 5, I cannot use Yahoo mail after attaching a file to a message. The program acts like there is a dialog box open and it is waiting for a choice to be made, but there is no dialog box.

    HI,
    BrowserPlus is causing problems when attaching files to Yahoo mail. It's not compatible with Safari 5.
    Read here for help to uninstall BrowserPlus:
    http://help.yahoo.com/l/us/yahoo/browserplus/uninstall.html
    Carolyn

  • Tracking Undelivered E-Mail using UTL_SMTP

    I am sending e-mail using UTL_SMTP. If there is any error in the e-mail delivery for e.g. say if the E-Mail bounced etc. then can i capture those events in my code?
    E-Mail can bounce back for any reason. for e.g. e-mail address is not valid. What all error we can capture using UTL_SMTP?
    Edited by: LostWorld on Jan 26, 2011 11:34 PM

    LostWorld wrote:
    I am sending e-mail using UTL_SMTP. If there is any error in the e-mail delivery for e.g. say if the E-Mail bounced etc. then can i capture those events in my code?Yes. But not via SMTP.
    The SMTP server receives the mail. It tells the client (your code, mail reader, whatever) that is has accepted the connection. That is the extent of the conversation. The SMTP protocol does not report on delivery steps, delivery status and so on.
    From a SMTP protocol perspective, the mail payload was delivered to that server. And that's it.
    The mail delivery runs into a problem. It could be on the SMTP server that accepted your mail. It could be a SMTP server on the other side of the world that is passing your e-mail along, 24 hours later.
    There are 2 types of problems. A soft bounce. This means that the server attempted delivery, and it failed - but the delivery attempt can be retried. For example, there could be a network problem (and this could shortly be rectified). In such a case, that SMTP server will look at the sender's address and send a soft bounce notification to the sender. It will describe the basic problem and how it will be handled - e.g. mail server may perform 3 more attempts at delivery in the next 12h and then hard bounce your e-mail.
    A hard bounce is a fatal error. For example, the SMTP server attempts to deliver your e-mail to its final destination (the mail server of the recipient's domain). That server says that the recipient (mail user) does not exist at that domain.
    In that case, the SMTP server will send the sender of that e-mail a hard bounce notification - informing the sender of what the fatal error is.
    So in order to get the bounce message, you need to supply a valid sender e-mail address when delivering that e-mail to the SMTP server. You then need to monitor that e-mail account (using the POP3 or IMAP protocols) for bounce e-mail notifications.
    However, even that will not indicate whether that original e-mail your code send was delivered successfully. And this is the bottom line - there are no guarantees. The SMTP and POP3/IMAP protocols cannot and do not guarantee you being able to determine whether or not an e-mail reached its intended destination.
    This is often why e-mails are send with a URL and a request that the recipient please click the URL when receiving the e-mail. That is the only method to determine whether the recipient received the e-mail, provided the recipient is willing to click that URL in that e-mail message.

  • I am having problems attaching files to my email using the latest Firefox 13.0.1, Comcast is my internet provider, but I did not have problem with Safari.

    Why am I having problems attaching files to my email using Firefox 13.0.1.?
    I am using a MAC, OS 10.6.8, and have Comcast as my internet provider. I noticed after I upgraded to Firefox 13.0.1 that I am having problems attaching files to my email. I do not experience the same problem with Safari, but I prefer to use Firefox, as all of my bookmarks and passwords are saved there. I just like the way Firefox works better than Safari.
    I am a free-lance graphic designer and rely on my internet connection to my customers. I need this resolved ASAP!

    Could you start by resetting the zoom level on the page? To do that, you can either:
    * Press Ctrl+0 (that's a zero) on the keyboard
    * View menu > Zoom > Reset
    You also can use zoom to increase/decrease the size from there. This article describes the various mouse, keyboard, and menu methods: [[Font size and zoom - increase the size of web pages]].
    Any luck?

  • Can't attach file in icloud webmail using firefox from windows or mac. any ideas?

    anyone else having trouble attaching file in icloud webmail using firefox or internet explorer from windows or mac. i was able to get it to work from safari on a mac, so i guess it must be a browser thing, only enabled or working in safari?

    I had the same problem since last Thursday.  I have tried and re-tried all of the settings suggested by the support posts but I can not get email to go out of me Outbox.

  • How to attach a file to a mail using htmldb

    Hi all,
    can u help me how to attach a file in htmldb.
    iam able to send a mail using the inbuilt package but unable to attach a file.
    advance thanks in helping out.

    The APEX_MAIL package doesn't support sending emails with attachments.
    See Send E-Mail with attachment from HTML DB for some alternatives.

  • Formatting emails:I am using UTL_SMTP package foe sending them.

    Hi
    I created a PL/SQL job to schedule email sending. The code looks like:
    DECLARE
    l_mailhost VARCHAR2(64) := 'qiudubcorrel001.qa.local';
    l_from VARCHAR2(64) := '[email protected]';
    l_to VARCHAR2(64) := '[email protected]';
    l_mail_conn UTL_SMTP.connection;
    BEGIN
    l_mail_conn := UTL_SMTP.open_connection(('10.253.14.240'), 25);
    UTL_SMTP.helo(l_mail_conn, '10.253.14.240');
    UTL_SMTP.mail(l_mail_conn, l_from);
    UTL_SMTP.rcpt(l_mail_conn, l_to);
    UTL_SMTP.data(l_mail_conn, 'Single string message.' || Chr(13));
    UTL_SMTP.quit(l_mail_conn);
    END;
    The code works fine, but now I want to add colour to my email, or introduce other formatting as well. How can I do that here?
    Thanks,
    Kamal

    Here you can find HTML formatting
    * PROCEDURE NAME : XX_EMAIL_FILES
    * DESCRIPTION:
    * ==========
    * Sends e-mail (text and/or html, either as a string or from a file)
    * to one or more recipients (including cc and/or bcc recipients), along with
    * up to 3 file attachments (text and/or binary; default is text/plain), using
    * the UTL_SMTP package to send the e-mail, the DBMS_LOB package to read
    * binary file attachments, and the UTL_ENCODE package to convert the binary
    * attachments to BASE64 for character string (non-binary) transmission.
    * BE AWARE THAT A COMMIT MAY BE DONE BY THIS ROUTINE.
    * PARAMETERS:
    * ==========
    * The complete parameter list for the xx_email_files procedure is shown below:
    * NAME TYPE DESCRIPTION
    * from_name IN Name and e-mail address to put in the From field
    * to_names IN Names and e-mail addresses for the To field (separated by
    * commas or semicolons)
    * subject IN Text string for Subject field
    * message IN Text string or text file name for Message, if any
    * html_message IN Html string or html file name for Message, if any
    * cc_names IN Names and e-mail addresses for the Cc field, if any
    * (separated by commas or semicolons)
    * bcc_names IN Names and e-mail addresses for the Bcc field, if any
    * (separated by commas or semicolons)
    * filename1 IN First unix file pathname to attach, if any
    * filetype1 IN Mime type of first file (defaults to 'text/plain')
    * filename2 IN Second unix file pathname to attach, if any
    * filetype2 IN Mime type of second file (defaults to 'text/plain')
    * filename3 IN Third unix file pathname to attach, if any
    * filetype3 IN Mime type of third file (defaults to 'text/plain')
    * Sample names and e-mail addresses are: arun (attaches @),
    * [email protected], , xxx , and
    * "xxx"
    * A sample call in PL/SQL is shown below, which sends a text and html message,
    * plus a text file and two binary files (note: the slash after "end;" must be
    * the first character on it's line):
    * begin
    * xx_email_files(from_name => '[email protected]' ,
    * to_names => '[email protected]',
    * subject => 'A test',
    * message => 'A TEST MESSAGE',
    * html_message => '
    A test message
    * filename1 => '/ora_appl/oracle/11.5.0/data/xxx.pdf',
    * filename2 => '/usr/tmp/115apug.pdf',
    * filetype2 => 'application/pdf',
    * filename3 => '',
    * filetype3 => 'image/jpeg'
    * end
    * If the message or html_message string has a file name in it (starting with
    * a forward slash), the text or html file is copied into the e-mail as the
    * message or html message; otherwise, the message or html_message is copied
    * into the e-mail as-is.
    * Attachment file types (mime types) that I've tested include:
    * text/plain,
    * text/html,
    * image/jpeg,
    * image/gif,
    * application/pdf,
    * application/msword
    * A list of mime types can be seen at:
    * http://www.webmaster-toolkit.com/mime-types.shtml
    * If the mime type does not begin with "text", it is assumed to be a binary
    * file that will be encoded as base64 before transmission.
    CREATE OR REPLACE PROCEDURE xx_email_files (
    from_name VARCHAR2,
    to_names VARCHAR2,
    subject VARCHAR2,
    MESSAGE VARCHAR2 DEFAULT NULL,
    html_message VARCHAR2 DEFAULT NULL,
    cc_names VARCHAR2 DEFAULT NULL,
    bcc_names VARCHAR2 DEFAULT NULL,
    filename1 VARCHAR2 DEFAULT NULL,
    filetype1 VARCHAR2 DEFAULT 'text/plain',
    filename2 VARCHAR2 DEFAULT NULL,
    filetype2 VARCHAR2 DEFAULT 'text/plain',
    filename3 VARCHAR2 DEFAULT NULL,
    filetype3 VARCHAR2 DEFAULT 'text/plain'
    IS
    -- Change the SMTP host name and port number below to your own values,
    -- if not localhost on port 25:
    smtp_host VARCHAR2 (256) := 'localhost';
    smtp_port NUMBER := 25;
    -- Change the boundary string, if needed, which demarcates boundaries of
    -- parts in a multi-part email, and should not appear inside the body of
    -- any part of the e-mail:
    boundary CONSTANT VARCHAR2 (256) := 'CES.Boundary.DACA587499938898';
    recipients VARCHAR2 (32767);
    directory_path VARCHAR2 (256);
    file_name VARCHAR2 (256);
    crlf VARCHAR2 (2) := CHR (13) || CHR (10);
    mesg VARCHAR2 (32767);
    conn UTL_SMTP.connection;
    l_length NUMBER;
    l_sub VARCHAR2 (32767);
    TYPE varchar2_table IS TABLE OF VARCHAR2 (256)
    INDEX BY BINARY_INTEGER;
    file_array varchar2_table;
    type_array varchar2_table;
    i BINARY_INTEGER;
    -- Function to return the next email address in the list of email addresses,
    -- separated by either a "," or a ";". From Oracle's demo_mail. The format
    -- of mailbox may be in one of these:
    -- someone@some-domain
    -- "Someone at some domain"
    -- Someone at some domain
    FUNCTION get_address (addr_list IN OUT VARCHAR2)
    RETURN VARCHAR2
    IS
    addr VARCHAR2 (256);
    i PLS_INTEGER;
    FUNCTION lookup_unquoted_char (str IN VARCHAR2, chrs IN VARCHAR2)
    RETURN PLS_INTEGER
    IS
    c VARCHAR2 (5);
    i PLS_INTEGER;
    len PLS_INTEGER;
    inside_quote BOOLEAN;
    BEGIN
    inside_quote := FALSE;
    i := 1;
    len := LENGTH (str);
    WHILE (i <= len)
    LOOP
    c := SUBSTR (str, i, 1);
    IF (inside_quote)
    THEN
    IF (c = '"')
    THEN
    inside_quote := FALSE;
    ELSIF (c = '\')
    THEN
    i := i + 1; -- Skip the quote character
    END IF;
    GOTO next_char;
    END IF;
    IF (c = '"')
    THEN
    inside_quote := TRUE;
    GOTO next_char;
    END IF;
    IF (INSTR (chrs, c) >= 1)
    THEN
    RETURN i;
    END IF;
    <>
    i := i + 1;
    END LOOP;
    RETURN 0;
    END;
    BEGIN
    addr_list := LTRIM (addr_list);
    i := lookup_unquoted_char (addr_list, ',;');
    IF (i >= 1)
    THEN
    addr := SUBSTR (addr_list, 1, i - 1);
    addr_list := SUBSTR (addr_list, i + 1);
    ELSE
    addr := addr_list;
    addr_list := '';
    END IF;
    i := lookup_unquoted_char (addr, '<');
    IF (i >= 1)
    THEN
    addr := SUBSTR (addr, i + 1);
    i := INSTR (addr, '>');
    IF (i >= 1)
    THEN
    addr := SUBSTR (addr, 1, i - 1);
    END IF;
    END IF;
    RETURN addr;
    END;
    -- Procedure to split a file pathname into its directory path and file name
    -- components.
    PROCEDURE split_path_name (
    file_path IN VARCHAR2,
    directory_path OUT VARCHAR2,
    file_name OUT VARCHAR2
    IS
    pos NUMBER;
    BEGIN
    -- Separate the filename from the directory name
    pos := INSTR (file_path, '/', -1);
    IF pos = 0
    THEN
    pos := INSTR (file_path, '\', -1);
    END IF;
    IF pos = 0
    THEN
    directory_path := NULL;
    ELSE
    directory_path := SUBSTR (file_path, 1, pos - 1);
    END IF;
    file_name := SUBSTR (file_path, pos + 1);
    END;
    -- Procedure to append a file's contents to the e-mail
    PROCEDURE append_file (
    directory_path IN VARCHAR2,
    file_name IN VARCHAR2,
    file_type IN VARCHAR2,
    conn IN OUT UTL_SMTP.connection
    IS
    generated_name VARCHAR2 (30)
    := 'CESDIR' || TO_CHAR (SYSDATE, 'HH24MISS');
    directory_name VARCHAR2 (30);
    file_handle UTL_FILE.file_type;
    bfile_handle BFILE;
    bfile_len NUMBER;
    pos NUMBER;
    read_bytes NUMBER;
    line VARCHAR2 (1000);
    DATA RAW (200);
    my_code NUMBER;
    my_errm VARCHAR2 (32767);
    BEGIN
    BEGIN
    -- Grant access to the directory, unless already defined, and open
    -- the file (as a bfile for a binary file, otherwise as a text file).
    BEGIN
    line := directory_path;
    SELECT dd.directory_name
    INTO directory_name
    FROM dba_directories dd
    WHERE dd.directory_path = line AND ROWNUM = 1;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    directory_name := generated_name;
    END;
    IF directory_name = generated_name
    THEN
    EXECUTE IMMEDIATE 'create or replace directory '
    || directory_name
    || ' as '''
    || directory_path
    || '''';
    EXECUTE IMMEDIATE 'grant read on directory '
    || directory_name
    || ' to public';
    END IF;
    IF SUBSTR (file_type, 1, 4) != 'text'
    THEN
    bfile_handle := BFILENAME (directory_name, file_name);
    bfile_len := DBMS_LOB.getlength (bfile_handle);
    pos := 1;
    DBMS_LOB.OPEN (bfile_handle, DBMS_LOB.lob_readonly);
    ELSE
    file_handle := UTL_FILE.fopen (directory_name, file_name, 'r');
    END IF;
    -- Append the file contents to the end of the message
    LOOP
    -- If it is a binary file, process it 57 bytes at a time,
    -- reading them in with a LOB read, encoding them in BASE64,
    -- and writing out the encoded binary string as raw data
    IF SUBSTR (file_type, 1, 4) != 'text'
    THEN
    IF pos + 57 - 1 > bfile_len
    THEN
    read_bytes := bfile_len - pos + 1;
    ELSE
    read_bytes := 57;
    END IF;
    DBMS_LOB.READ (bfile_handle, read_bytes, pos, DATA);
    UTL_SMTP.write_raw_data (conn, UTL_ENCODE.base64_encode (DATA));
    pos := pos + 57;
    IF pos > bfile_len
    THEN
    EXIT;
    END IF;
    -- If it is a text file, get the next line of text, append a
    -- carriage return / line feed to it, and write it out
    ELSE
    UTL_FILE.get_line (file_handle, line);
    UTL_SMTP.write_data (conn, line || crlf);
    END IF;
    END LOOP;
    -- Output any errors, except at end when no more data is found
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    my_code := SQLCODE;
    my_errm := SQLERRM;
    DBMS_OUTPUT.put_line ('Error code ' || my_code || ': ' || my_errm);
    END;
    -- Close the file (binary or text)
    IF SUBSTR (file_type, 1, 4) != 'text'
    THEN
    DBMS_LOB.CLOSE (bfile_handle);
    ELSE
    UTL_FILE.fclose (file_handle);
    END IF;
    IF directory_name = generated_name
    THEN
    EXECUTE IMMEDIATE 'drop directory ' || directory_name;
    END IF;
    END;
    BEGIN
    -- Load the three filenames and file (mime) types into an array for
    -- easier handling later
    file_array (1) := filename1;
    file_array (2) := filename2;
    file_array (3) := filename3;
    type_array (1) := filetype1;
    type_array (2) := filetype2;
    type_array (3) := filetype3;
    -- Open the SMTP connection and set the From and To e-mail addresses
    conn := UTL_SMTP.open_connection (smtp_host, smtp_port);
    UTL_SMTP.helo (conn, smtp_host);
    recipients := from_name;
    UTL_SMTP.mail (conn, get_address (recipients));
    recipients := to_names;
    WHILE recipients IS NOT NULL
    LOOP
    UTL_SMTP.rcpt (conn, get_address (recipients));
    END LOOP;
    recipients := cc_names;
    WHILE recipients IS NOT NULL
    LOOP
    UTL_SMTP.rcpt (conn, get_address (recipients));
    END LOOP;
    recipients := bcc_names;
    WHILE recipients IS NOT NULL
    LOOP
    UTL_SMTP.rcpt (conn, get_address (recipients));
    END LOOP;
    UTL_SMTP.open_data (conn);
    -- Build the start of the mail message
    mesg :=
    'Date: '
    || TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss')
    || crlf
    || 'From: '
    || from_name
    || crlf
    || 'Subject: '
    || subject
    || crlf
    || 'To: '
    || to_names
    || crlf;
    IF cc_names IS NOT NULL
    THEN
    mesg := mesg || 'Cc: ' || cc_names || crlf;
    END IF;
    IF bcc_names IS NOT NULL
    THEN
    mesg := mesg || 'Bcc: ' || bcc_names || crlf;
    END IF;
    mesg :=
    mesg
    || 'Mime-Version: 1.0'
    || crlf
    || 'Content-Type: multipart/mixed; boundary="'
    || boundary
    || '"'
    || 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;
    UTL_SMTP.write_data (conn, mesg);
    -- Write the text message or message file, if any
    IF MESSAGE IS NOT NULL
    THEN
    mesg :=
    || boundary
    || 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;
    UTL_SMTP.write_data (conn, mesg);
    IF SUBSTR (MESSAGE, 1, 1) = '/'
    THEN
    split_path_name (MESSAGE, directory_path, file_name);
    append_file (directory_path, file_name, 'text', conn);
    UTL_SMTP.write_data (conn, crlf);
    ELSE
    UTL_SMTP.write_data (conn, MESSAGE || crlf);
    END IF;
    END IF;
    IF html_message IS NOT NULL
    THEN
    mesg :=
    || boundary
    || crlf
    || 'Content-Type: text/html; name="message.html"; charset=US-ASCII'
    || crlf
    || 'Content-Disposition: inline; filename="message.html"'
    || crlf
    || 'Content-Transfer-Encoding: 7bit'
    || crlf
    || crlf;
    UTL_SMTP.write_data (conn, mesg);
    IF SUBSTR (html_message, 1, 1) = '/'
    THEN
    split_path_name (html_message, directory_path, file_name);
    append_file (directory_path, file_name, 'text', conn);
    UTL_SMTP.write_data (conn, crlf);
    ELSE
    UTL_SMTP.write_data (conn, html_message || crlf);
    END IF;
    END IF;
    -- Append the files
    FOR i IN 1 .. 3
    LOOP
    -- If the filename has been supplied ...
    IF file_array (i) IS NOT NULL
    THEN
    split_path_name (file_array (i), directory_path, file_name);
    -- Generate the MIME boundary line according to the file (mime) type
    -- specified.
    mesg := crlf || '--' || boundary || crlf;
    SELECT INSTR (file_name, '.')
    INTO l_length
    FROM DUAL;
    SELECT SUBSTR (file_name, 1, l_length - 1) || '.pdf'
    INTO l_sub
    FROM DUAL;
    IF SUBSTR (type_array (i), 1, 4) != 'text'
    THEN
    mesg :=
    mesg
    || 'Content-Type: '
    || type_array (i)
    || '; name="'
    || file_name
    || '"'
    || crlf
    || 'Content-Disposition: attachment; filename="'
    || file_name
    || '"'
    || crlf
    || 'Content-Transfer-Encoding: base64'
    || crlf
    || crlf;
    ELSE
    mesg :=
    mesg
    || 'Content-Type: application/octet-stream; name="'
    || file_name
    || '"'
    || crlf
    || 'Content-Disposition: attachment; filename="'
    || file_name
    || '"'
    || crlf
    || 'Content-Transfer-Encoding: 7bit'
    || crlf
    || crlf;
    END IF;
    UTL_SMTP.write_data (conn, mesg);
    -- Append the file contents to the end of the message
    append_file (directory_path, file_name, type_array (i), conn);
    UTL_SMTP.write_data (conn, crlf);
    END IF;
    END LOOP;
    -- Append the final boundary line
    mesg := crlf || '--' || boundary || '--' || crlf;
    UTL_SMTP.write_data (conn, mesg);
    -- Close the SMTP connection
    UTL_SMTP.close_data (conn);
    UTL_SMTP.quit (conn);
    END;
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • How to put an image to any part of an e-mail using UTL_SMTP

    We need to send an e-mail with the following format.
    |COMPANY LOGO (JPEC IMAGE)          |
    |                                    |
    |                                    |
    |              HTML table            |
    |                                    |
    |                                    |
    ------------------------------------The exact format is shown here: http://postimage.org/image/76v4e5tmd/
    Above the Automatic Payment Advice is the JPEG image.
    How do we CONSTRUCT THIS e-mail? Our DB is a 10g R2. We use UTL_SMTP. Problem is how to insert an image to any part of the e-mail (not as a separate attachment)?
    Edited by: Channa on May 24, 2012 5:51 AM

    Yes. It is possible. Read this posts of Billy Verreynne to uderstand the MIME format.
    Re: Sending HTML mail with inline/embeded images (My code is constructed on this input)
    embeded image in email body in pl/sql
    DECLARE
      /*LOB operation related varriables */
      v_src_loc  BFILE := BFILENAME('TEMP', 'otn.jpg');
      l_buffer   RAW(54);
      l_amount   BINARY_INTEGER := 54;
      l_pos      INTEGER := 1;
      l_blob     BLOB := EMPTY_BLOB;
      l_blob_len INTEGER;
      v_amount   INTEGER;
      /*UTL_SMTP related varriavles. */
      v_connection_handle  UTL_SMTP.CONNECTION;
      v_from_email_address VARCHAR2(30) := '[email protected]';
      v_to_email_address   VARCHAR2(30) := '[email protected]';
      v_smtp_host          VARCHAR2(30) := 'x.xxx.xxx.xxx'; --My mail server, replace it with yours.
      v_subject            VARCHAR2(30) := 'Your Test Mail';
      l_message            VARCHAR2(32767) := '<html>
    <meta http-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii">
    <body background=3D"cid:[email protected]">
    ..rest of mail
    </body>
    </html>
      /* This send_header procedure is written in the documentation */
      PROCEDURE send_header(pi_name IN VARCHAR2, pi_header IN VARCHAR2) AS
      BEGIN
        UTL_SMTP.WRITE_DATA(v_connection_handle,
                            pi_name || ': ' || pi_header || UTL_TCP.CRLF);
      END;
    BEGIN
      /*Preparing the LOB from file for attachment. */
      DBMS_LOB.OPEN(v_src_loc, DBMS_LOB.LOB_READONLY); --Read the file
      DBMS_LOB.CREATETEMPORARY(l_blob, TRUE); --Create temporary LOB to store the file.
      v_amount := DBMS_LOB.GETLENGTH(v_src_loc); --Amount to store.
      DBMS_LOB.LOADFROMFILE(l_blob, v_src_loc, v_amount); -- Loading from file into temporary LOB
      l_blob_len := DBMS_LOB.getlength(l_blob);
      /*UTL_SMTP related coding. */
      v_connection_handle := UTL_SMTP.OPEN_CONNECTION(host => v_smtp_host);
      UTL_SMTP.HELO(v_connection_handle, v_smtp_host);
      UTL_SMTP.MAIL(v_connection_handle, v_from_email_address);
      UTL_SMTP.RCPT(v_connection_handle, v_to_email_address);
      UTL_SMTP.OPEN_DATA(v_connection_handle);
      send_header('From', '"Sender" <' || v_from_email_address || '>');
      send_header('To', '"Recipient" <' || v_to_email_address || '>');
      send_header('Subject', v_subject);
      --MIME header.
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'MIME-Version: 1.0' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-Type: multipart/related; ' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          ' boundary= "' || 'SAUBHIK.SECBOUND' || '"' ||
                          UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
      -- Mail Body
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          '--' || 'SAUBHIK.SECBOUND' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-Type: text/html;' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          ' charset=US-ASCII' || UTL_TCP.CRLF);
    UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-Transfer-Encoding: quoted-printable' || UTL_TCP.CRLF);                     
      UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle, l_message || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
      -- Mail Attachment
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          '--' || 'SAUBHIK.SECBOUND' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-Disposition: inline; filename="otn.jpg"' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-Type: image/jpg; name="otn.jpg"' ||
                          UTL_TCP.CRLF);
    UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-ID: <[email protected]>; ' ||
                          UTL_TCP.CRLF);                     
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          'Content-Transfer-Encoding: base64' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
      /* Writing the BLOL in chunks */
      WHILE l_pos < l_blob_len LOOP
        DBMS_LOB.READ(l_blob, l_amount, l_pos, l_buffer);
        UTL_SMTP.write_raw_data(v_connection_handle,
                                UTL_ENCODE.BASE64_ENCODE(l_buffer));
        UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
        l_buffer := NULL;
        l_pos    := l_pos + l_amount;
      END LOOP;
      UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
      -- Close Email
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          '--' || 'SAUBHIK.SECBOUND' || '--' || UTL_TCP.CRLF);
      UTL_SMTP.WRITE_DATA(v_connection_handle,
                          UTL_TCP.CRLF || '.' || UTL_TCP.CRLF);
      UTL_SMTP.CLOSE_DATA(v_connection_handle);
      UTL_SMTP.QUIT(v_connection_handle);
      DBMS_LOB.FREETEMPORARY(l_blob);
      DBMS_LOB.FILECLOSE(v_src_loc);
    EXCEPTION
      WHEN OTHERS THEN
        UTL_SMTP.QUIT(v_connection_handle);
        DBMS_LOB.FREETEMPORARY(l_blob);
        DBMS_LOB.FILECLOSE(v_src_loc);
        RAISE;
    END;Otn logo is in my database server and It will embade otn logo all over the mail body!.
    Edited by: Saubhik on May 24, 2012 9:06 PM
    Changed the original IP and email address. I should have done this earlier!: Saubhik on May 25, 2012 11:20 AM

Maybe you are looking for

  • Nokia 7230 - How to insert a phone number from Con...

    I know this is an issue with some other models, but HOW do I insert a phone number from my contacts into a text message? -If I go to Phonebook and "copy" number, then I try to paste it into my message, I get an answer that there is nothing to paste.

  • AIF webdynpro for Java Prerequsites

    Hi,      What are the prerequsite for AIF development with Portal 6.0 WebAS 640 (SP17). NWDS Version? ADS version? ALD Version? any other required componets and their versions? If you could point me to some documentation on this that would also be he

  • Iwork 09 password protection for pages & numbers files

    I created a numbers file (iWork 09) on iMac that is password protected.  I sent the file to my iPad 2 and the first time i opened the file via ipad 2, it prompted me for my password, but now every time thereafter when I open the file in my ipad 2, it

  • Occi.h missing from $ORACLE_HOME

    dear All, We have an oracle 9i installed on AXI5l I created a simple program cpp to try the occi. when i use proc iname=simple.cpp include=/orasys/ora9i/app/oracle/product/9.2.0.1/rdbms/demo/occi.h Pro*C/C++: Release 9.2.0.1.0 - Production on Mon Mar

  • Help please -SQL

    hey, My cardType is entered into the Title Table in the database for some reason I can't see how its doing this. thanx String radiob = request.getParameter("radiobutton"); String Username = request.getParameter("Username"); String Password = request.