Subject in utl_smtp

Hi
we use utl_smtp to send html emails with special characters as 'ěřšý' and it works fine. can me anybody tell if it is possible to use this characters in the email subject?
we use
utl_smtp.write_data(c, 'MIME-version: 1.0' || utl_tcp.crlf);
utl_smtp.write_data(c, 'Content-Type: text/html; charset=windows-1250;' ||utl_tcp.crlf);
utl_smtp.write_raw_data(c, utl_raw.cast_to_raw('Subject: '|| 'Další pokus řekněme.'));
-- utl_smtp.write_data(c, 'Subject: '|| 'Další pokus řekněme.', 'MIME=("EE8MSWIN1250"' );
-- utl_smtp.write_raw_data(c, utl_raw.cast_to_raw(CONVERT('Subject: '|| 'Další pokus řekněme.' ,'EE8MSWIN1250')));
can somebody help me to solve it?
thanks
jura

Hello Jura,
the Subject always has to be encoded. Have a look at UTL_ENCODE.MIMEHEADER_ENCODE
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_encode.htm#i999461
To find out about this it also might be helpful to view the raw text of a mail sent from your personal mail client (Most clients can, but I think Outlook cannot). The subject line should look similar to
Subject: =?iso-8859-1?Q?Fahrplan=E4nderungen_KBS_930_(M=FCnchen_-_Landshut_-_Regen?= =?iso-8859-1?Q?sburg)?=For a german subject line "Fahrplanänderungen KBS 930 München - Landshut - Regensburg"
Regards
Marcus

Similar Messages

  • Send email from the server

    I need to send email from the database.
    Two ways that I am familiar with -
    1. using VB/ODBC controls;
    2. dbms_pipe
    Anyone knows a more 'direct' solution?
    Regards
    Anatoliy Smirnov
    null

    by the way how can u send attchments with mails from database.
    chetan
    try this...(thanks for the subject line help)
    the first message line will be read by non MIME compliant readers, the second message line with be in the body of the note, the nest 2 (third and fourth) will come in as attachments ( text ). Change the Content-type for things like word docs or other 8bit docs (Content-type: application/msword) and write_raw_data for the 8Bit parts
    CREATE OR REPLACE PROCEDURE send_mail_test (sender IN VARCHAR2,
    recipient IN VARCHAR2, subject IN VARCHAR2,
    message IN VARCHAR2)
    IS
    mailhost VARCHAR2(30) := 'smtp.naxs.net';
    mail_conn utl_smtp.connection;
    cv_cCRLF VARCHAR2(10) := UTL_TCP.CRLF;
    lv_message varchar2(4000);
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, sender);
    utl_smtp.rcpt(mail_conn, recipient);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn,'From: ' | | sender | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'To: ' | | recipient | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Subject:' | | subject | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'MIME-Version: 1.0' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Content-Type: multipart/mixed; ');
    utl_smtp.write_data(mail_conn,'boundary="NextPart_000_01C002D3.EB460626"' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| |' first mess part'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| | ' second mess part'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Content-Type: text/plain; charset=us-ascii'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| | ' third mess part'| |cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Content-Type: text/plain; charset=us-ascii'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| | ' fourth mess part'| |cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626--' | | cv_cCRLF);
    utl_smtp.close_data(mail_conn);
    -- utl_smtp.data(mail_conn, message);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN OTHERS
    THEN
    DECLARE
    error_code NUMBER := SQLCODE;
    error_msg VARCHAR2(2000) := SQLERRM;
    error_info VARCHAR2(30);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('We have an error: '| |error_code| |' '| |error_msg);
    END;
    END;
    show errors;
    null

  • Sending a mail from oracle database

    Hi,
    I have a requirement to send a mail from oracle database.I use UTL_TCP package for this.Although my procedure is executed successfully,i dont get the mails in my inbox.Please help me to figure out a solution.
    Thanks in advance....

    Hi, you must use UTL_SMTP package for send emails, it has more performance and features for debug. You must look the next code, this is a example for send emails.
    DECLARE
    c UTL_SMTP.CONNECTION;
    PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
    BEGIN
    UTL_SMTP.WRITE_DATA(c, name || ': ' || header || UTL_TCP.CRLF);
    END;
    BEGIN
    c := UTL_SMTP.OPEN_CONNECTION('smtp-server.acme.com');
    UTL_SMTP.HELO(c, 'foo.com');
    UTL_SMTP.MAIL(c, '[email protected]');
    UTL_SMTP.RCPT(c, '[email protected]');
    UTL_SMTP.OPEN_DATA(c);
    send_header('From', '"Sender" <[email protected]>');
    send_header('To', '"Recipient" <[email protected]>');
    send_header('Subject', 'Hello');
    UTL_SMTP.WRITE_DATA(c, UTL_TCP.CRLF || 'Hello, world!');
    UTL_SMTP.CLOSE_DATA(c);
    UTL_SMTP.QUIT(c);
    EXCEPTION
    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    BEGIN
    UTL_SMTP.QUIT(c);
    EXCEPTION
    WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
    NULL; -- When the SMTP server is down or unavailable, we don't have
    -- a connection to the server. The QUIT call will raise an
    -- exception that we can ignore.
    END;
    raise_application_error(-20000,
    'Failed to send mail due to the following error: ' || sqlerrm);
    END;
    Also review the next link for get more information about the UTL_SMTP packege.
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_smtp.htm#sthref15587
    Regards.

  • Problems setting up ACL in 11g

    Hello,
    we recently updated from 10g to 11g. In our db we have a job, which calls a procedure, which checks if all mails from our application have been sent probably, if not it sends out a mail via a different mail server to admins, so they can check what the issue was.
    This worked fine in 10g. In 11g I've learned I need to set up the ACL to be able to connect to the mail Server. This is what I've done:
    Since the job, mentioned above is running for user sys i set up the ACL for the user sys.
    begin
      if dbms_db_version.ver_le_10_2 then
        null;
      else
        begin
          dbms_network_acl_admin.drop_acl(
            acl =>         'apex-network.xml'
        exception
          when others then null;
        end;
        dbms_network_acl_admin.create_acl(
          acl =>         'apex-network.xml',
          description => 'Network-Connects for system check',
          principal =>   'SYS',
          is_grant =>    true,
          privilege =>   'connect'
        DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
          acl =>         'apex-network.xml',
          principal =>   'SYS',
          is_grant  =>   true,
          privilege =>   'resolve'
        dbms_network_acl_admin.assign_acl(
          acl =>         'apex-lcmcc-network.xml',
          host =>        '123.456.78.99'
      end if;
    end;
    show error
    commit;
    The statement completed successfully. And i checked if the access is granted with the following statement:
    SELECT
    FROM
      user_network_acl_privileges,
      TABLE(DBMS_NETWORK_ACL_UTILITY.DOMAINS('123.456.78.99'))
    ORDER BY
      DBMS_NETWORK_ACL_UTILITY.DOMAIN_LEVEL(column_value) desc,
      lower_port,                                             
      upper_port;
    I see now for the configured host and all subdomains user sys has the privillege resolve and connect granted.
    When i run the  procedure, which should sent the mails i still get the error ORA-24247: network access denied by access control list (ACL).
    Here is the relevant code from the procedure:
    BEGIN
              c := UTL_SMTP.OPEN_CONNECTION('123.456.78.99');
              UTL_SMTP.HELO(c, 'xxx.de');
              UTL_SMTP.MAIL(c, '[email protected]');
              UTL_SMTP.RCPT(c, p_rcpt);
              UTL_SMTP.OPEN_DATA(c);
              send_header('From',    p_from);
              send_header('To',      p_rcpt);
              send_header('Subject', p_subject);
              UTL_SMTP.WRITE_DATA(c, UTL_TCP.CRLF||p_message );
              UTL_SMTP.CLOSE_DATA(c);
              UTL_SMTP.QUIT(c);
            EXCEPTION
              WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
                BEGIN
                  UTL_SMTP.QUIT(c);
                EXCEPTION
                  WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
                    NULL; -- When the SMTP server is down or unavailable, we don't have
                          -- a connection to the server. The QUIT call will raise an
                          -- exception that we can ignore.
                END;
                raise_application_error(-20000,
                  'Failed to send mail due to the following error: ' || sqlerrm);
            END;
    Please forgive me if i miss out important information you need to assist me in this endavor, i will try to deliver them shortly.
    Any sugesstions are much apreciated.
    Thanks in advance.

    >Since the job, mentioned above is running for user sys i set up the ACL for the user sys.
    SYS schema is reserved for Oracle maintenance & upgrades.
    You should NEVER make or modify objects within the SYS schema.

  • General OEM Question

    Can anyone give me a general idea I have created one simple job where I count the number of rows in a table but now I would like to send the output to my e-mail. Also if anyone has some sample code that can give me an idea on how to creat other jobs like checking to see if the database is up and running and if not e-mail me. Thanks in advance.
    Matt

    Hi,
    one chance over the PACKAGE utl_smtp .
    * OVERVIEW
    * This package provides SMTP client-side access functionality in PL/SQL.
    * With this package, a PL/SQL program can send electronic mails via SMTP.
    * This package does not allow the PL/SQL program to receive e-mails via
    * SMTP. The user of this package should be familiar with the SMTP protocol
    * as defined in RFC 821 and RFC 1869.
    * This package is meant to provide an API to SMTP protocol directly. Users
    * may find it useful to define additional helper routines to encapsulate
    * the interaction with a SMTP server.
    * USES
    * A SMTP connection is initiated by a call to open_connection, which
    * returns a SMTP connection. After a connection is established, the
    * following calls are required to send a mail:
    * helo() - identify the domain of the sender
    * mail() - start a mail, specify the sender
    * rcpt() - specify the recipient
    * open_data() - start the mail body
    * write_data() - write the mail body (multiple calls allowed)
    * close_data() - close the mail body and send the mail
    * The SMTP connection is closed by calling quit().
    * A note on API style and raising PL/SQL exception:
    * Most of the API has a function form and a procedure form. The function
    * form returns the reply message after the command is sent, in the form
    * of "XXX <an optional reply message>", where XXX is the reply code.
    * The procedure form of the same API calls the function form of the API,
    * checks the reply code and raises transient_error or permanent_error
    * exception if the reply code is in 400 or 500 range. The function form
    * of the API does not raise either of the 2 exceptions.
    * All API may raise invalid_operation exception if it is called in either
    * of the situations:
    * 1. calling API other than write_data(), write_raw_data() or close_data()
    * after open_data(0 is called, or
    * 2. calling write_data(), write_raw_data() or close_data() without
    * first calling open_data()
    * EXAMPLES
    * Retrieve the home page from http://www.acme.com/
    * DECLARE
    * c utl_smtp.connection;
    * PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
    * BEGIN
    * utl_smtp.write_data(c, name || ': ' || header || utl_tcp.CRLF);
    * END;
    * BEGIN
    * c := utl_smtp.open_connection('smtp-server.acme.com');
    * utl_smtp.helo(c, 'foo.com');
    * utl_smtp.mail(c, '[email protected]');
    * utl_smtp.rcpt(c, '[email protected]');
    * utl_smtp.open_data(c);
    * send_header('From', '"Sender" <[email protected]>');
    * send_header('To', '"Recipient" <[email protected]>');
    * send_header('Subject', 'Hello');
    * utl_smtp.write_data(c, utl_tcp.CRLF || 'Hello, world!');
    * utl_smtp.close_data(c);
    * utl_smtp.quit(c);
    * EXCEPTION
    * WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    * utl_smtp.quit(c);
    * raise_application_error(-20000,
    * 'Failed to send mail due to the following error: ' || sqlerrm);
    * END;
    * SMTP connection type
    TYPE connection IS RECORD (
    host VARCHAR2(255), -- Host name of SMTP server
    port PLS_INTEGER, -- Port number of SMTP server
    tx_timeout PLS_INTEGER, -- Transfer time-out (in seconds)
    private_tcp_con utl_tcp.connection, -- For internal use only
    private_state PLS_INTEGER -- For internal use only
    * SMTP reply structure
    regards
    Karl-Heinz Schnvpel

  • ORACLE 11g R1 Email Alerts

    Hi
    I would like to send sql staments result set in a email to mutiple recepients. Result can be in body of email /xls attachment. is there any pl.sql scripts available to perform same in oracle 11g r1.
    Thanks
    Raj

    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/u_smtp.htm
    Examples
    The following example illustrates how UTL_SMTP is used by an application to send e-mail. The application connects to an SMTP server at port 25 and sends a simple text message.
    DECLARE
      c UTL_SMTP.CONNECTION;
      PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
      BEGIN
        UTL_SMTP.WRITE_DATA(c, name || ': ' || header || UTL_TCP.CRLF);
      END;
    BEGIN
      c := UTL_SMTP.OPEN_CONNECTION('smtp-server.acme.com');
      UTL_SMTP.HELO(c, 'foo.com');
      UTL_SMTP.MAIL(c, '[email protected]');
      UTL_SMTP.RCPT(c, '[email protected]');
      UTL_SMTP.OPEN_DATA(c);
      send_header('From',    '"Sender" <[email protected]>');
      send_header('To',      '"Recipient" <[email protected]>');
      send_header('Subject', 'Hello');
      UTL_SMTP.WRITE_DATA(c, UTL_TCP.CRLF || 'Hello, world!');
      UTL_SMTP.CLOSE_DATA(c);
      UTL_SMTP.QUIT(c);
    EXCEPTION
      WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
        BEGIN
          UTL_SMTP.QUIT(c);
        EXCEPTION
          WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
            NULL; -- When the SMTP server is down or unavailable, we don't have
                  -- a connection to the server. The QUIT call will raise an
                  -- exception that we can ignore.
        END;
        raise_application_error(-20000,
          'Failed to send mail due to the following error: ' || sqlerrm);
    END;

  • When ever employee position changed, an alert should send an email

    we have one requirement...
    when ever any employee position changed, it should send an email ..how to do this one? any idea?
    employee positions are recorded in PER_ALL_ASSIGNMENTS_F table, so if we create event alert on this table ( update ). event alert fires if there is any update to the table...but i want, only alert should send mail, when position column got updated in that table...
    is it possible????

    Oracle provides standard API’s to harness the databases SMTP server capabilities in sending emails. All email services are wrapped under package: UTL_SMTP. The protocol consists of a set of commands for an email client to dispatch emails to a SMTP server. The UTL_SMTP package provides interfaces to the SMTP commands. For many of the commands, the package provides both a procedural and a functional interface. The functional form returns the reply from the server for processing by the client. The procedural form checks the reply and will raise an exception if the reply indicates a transient (400-range reply code) or permanent error (500-range reply code). Otherwise, it discards the reply.
    c := UTL_SMTP.OPEN_CONNECTION('<server>.unix.us.ups.com');
    UTL_SMTP.HELO(c, '<server>.unix.us.ups.com');
    UTL_SMTP.MAIL(c, l_recepient);
    UTL_SMTP.RCPT(c, l_recepient);
    UTL_SMTP.OPEN_DATA(c);
    send_header('From', p_from);
    send_header('To', l_recepient);
    send_header('Subject', p_subject);
    UTL_SMTP.WRITE_DATA(c, UTL_TCP.CRLF || p_message);
    UTL_SMTP.CLOSE_DATA(c);
    UTL_SMTP.QUIT(c);

  • ORA-20002: 501 Bad syntax error

    Hi,
    I intend to send a simple smtp mail using the builtin UTL_SMTP package.
    But i get the following error:-
    ORA-20002: 501 Bad syntax error
    Here is my code:-
    CREATE OR REPLACE PROCEDURE mail
    IS
    BEGIN
    DECLARE
    v_connection UTL_SMTP.CONNECTION;
    BEGIN v_connection := UTL_SMTP.OPEN_CONNECTION(<my host here>,25);
    dbms_output.put_line('Connection Opened');
    UTL_SMTP.HELO(v_connection,<my host here>);
    dbms_output.put_line('After calling helo');
    UTL_SMTP.MAIL(v_connection,'[email protected]');
    dbms_output.put_line('Sender set');
    UTL_SMTP.RCPT(v_connection,'[email protected]');
    dbms_output.put_line('Recipient Set');
    UTL_SMTP.DATA(v_connection,'Sent From PL/SQL');
    dbms_output.put_line('Message body set');
    UTL_SMTP.QUIT(v_connection);
    dbms_output.put_line('Connection Closed');
    end;
    END;
    Here is the output:-
    SQL> exec mail
    Connection Opened
    After calling helo
    BEGIN mail; END;
    ERROR at line 1:
    ORA-20002: 501 Bad address syntax
    ORA-06512: at "SYS.UTL_SMTP", line 86
    ORA-06512: at "SYS.UTL_SMTP", line 204
    ORA-06512: at "ADMIN.MAIL", line 13
    ORA-06512: at line 1
    I tried sending mails to my smtp server via java mailing API and i am
    successful. So i am wondering wat i am doing wrong up there in Oracle.
    I have JServer enabled, i also ran the initplsj.sql successfully.
    Please help.
    Regards,
    Leo.

    Hi APC,
    Yep HELO returns 250. Here is the code i use followed by the output. I use valid e-mail addresses(changed them here cz they belong to real ppl :) ). Again, i am able to send mails via java mailing API's, to the same recipietn from same sender via same smtp server.
    Code :------
    CREATE OR REPLACE PROCEDURE mail
    IS
    v_connection UTL_SMTP.CONNECTION;
    value UTL_SMTP.reply;
    PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
    BEGIN
    UTL_SMTP.write_data(v_connection, name || ': ' || header || utl_tcp.CRLF);
    END;
    BEGIN
    v_connection := UTL_SMTP.OPEN_CONNECTION('smtp.server',25);
    dbms_output.put_line('Connection Opened');
    dbms_output.put_line('before calling helo');
    value := UTL_SMTP.HELO(v_connection,'smtp.server');
    dbms_output.put_line('after calling helo');
    dbms_output.put_line('code ' || value.code);
    dbms_output.put_line('before Sender is set');
    value := UTL_SMTP.MAIL(v_connection,'[email protected]');
    dbms_output.put_line('code ' || value.code);
    dbms_output.put_line('text ' || value.text);
    UTL_SMTP.RCPT(v_connection,'[email protected]');
    dbms_output.put_line('Recipient Set');
    UTL_SMTP.open_data(v_connection);
    send_header('From','"Sender" <[email protected]>');
    send_header('To','"Recipient" <[email protected]>');
    send_header('Subject','Hello');
    UTL_SMTP.write_data(v_connection, UTL_TCP.CRLF || 'Hello, world!');
    UTL_SMTP.close_data(v_connection);
    dbms_output.put_line('Message body set');
    UTL_SMTP.QUIT(v_connection);
    dbms_output.put_line('Connection Closed');
    END;
    Output:--------
    Connection Opened
    before calling helo
    after calling helo
    code 250
    before Sender is set
    code 501
    text Bad address syntax
    Looking forward to hearing from youself. :)
    Reagrds,
    Leo.

  • Installing utl packages

    how i can install utl packages in oracle 8i.
    eg. i want to use utl.smtp package for sending mails from my forms, but it gives me an error saying that dentifier 'UTL_SMTP.CONNECTION' must be declared
    can u please help me.
    uday

    Hi,
    You have to compile the package ORACLE_HOME/rdbms/utlsmtp.sql as sys.
    Here is an example on how call/use package utl_smtp:
    DECLARE
         smtp_out utl_smtp.connection ;
         PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
         BEGIN
              utl_smtp.write_data(smtp_out, name || ': ' || header || utl_tcp.CRLF);
         END ;
         BEGIN
              smtp_out := utl_smtp.open_connection('smtp.swipnet.se');
              utl_smtp.helo(smtp_out, 'sune.se');
              utl_smtp.mail(smtp_out, '[email protected]');
              utl_smtp.rcpt(smtp_out, '[email protected]');
              utl_smtp.open_data(smtp_out);
              send_header('From', '"Sender" <[email protected]>');
              send_header('To', '"Recipient" <[email protected]>');
              send_header('Subject', 'Test');
              utl_smtp.write_data(smtp_out, utl_tcp.CRLF || 'Hello world!');
              utl_smtp.close_data(smtp_out);
              utl_smtp.quit(smtp_out);
         EXCEPTION
              WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
                   utl_smtp.quit(smtp_out);
              WHEN others THEN
                   RAISE_APPLICATION_ERROR(-20100, 'Fail! Cannot send e-mail: ' || sqlerrm) ;
    END ;
    Regards - Tommy

  • Reg : Sending mails from PL/SQL

    Hello,
    I've written the following code for sending mails from PL/SQL.
    But the application gets hanged during compilation itself. Could
    any of u please tell me why it's happening and what is wrong in
    this and suggest me how to do it ??????
    CREATE OR REPLACE PROCEDURE SEND_MAIL
    IS
    msg_from varchar2(50) := '[email protected]';
    msg_to varchar2(50) := '[email protected]';
    msg_subject varchar2(100) := 'E-Mail message from your database';
    msg_text varchar2(1000) := '';
    c utl_tcp.connection;
    rc integer;
    BEGIN
    c := utl_tcp.open_connection('172.16.48.1', 80); -- open the
    SMTP
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'HELO localhost');
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'MAIL FROM: '||msg_from);
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'RCPT TO: '||msg_to);
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'DATA'); -- Start message body
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'Subject: '||msg_subject);
    rc := utl_tcp.write_line(c, '');
    rc := utl_tcp.write_line(c, msg_text);
    rc := utl_tcp.write_line(c, '.'); -- End of message body
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    rc := utl_tcp.write_line(c, 'QUIT');
    dbms_output.put_line(utl_tcp.get_line(c, TRUE));
    utl_tcp.close_connection(c); -- Close the connection
    EXCEPTION
    when others then
    raise_application_error(-20000,'Unable to send e-mail message
    from pl/sql');
    END;
    Awaiting for ur reply,
    Thanks in Advance...
    Srinivas

    FUNCTION Send_Mail ( sender IN VARCHAR2
         , recipient IN VARCHAR2
         , subject IN VARCHAR2
         , message IN VARCHAR2)
         RETURN BOOLEAN IS
         lv_mailhost VARCHAR2(30) := 'mailserver';
         l_mail_conn utl_smtp.connection;
         lv_crlf VARCHAR2(2):= CHR( 13 ) || CHR( 10 );
    BEGIN
         l_mail_conn := utl_smtp.open_connection ( lv_mailhost
              , 25);
         utl_smtp.helo ( l_mail_conn
                        , lv_mailhost);
         utl_smtp.mail ( l_mail_conn
                        , sender);
         utl_smtp.rcpt ( l_mail_conn
                        , recipient);
         utl_smtp.open_data (l_mail_conn);
         utl_smtp.write_data ( l_mail_conn
                                  , 'From: '
                                  || sender
                                  || lv_crlf);
         utl_smtp.write_data ( l_mail_conn
                                  , 'To: '
                                  || recipient
                                  || lv_crlf);
         utl_smtp.write_raw_data ( l_mail_conn
    utl_raw.cast_to_raw ( 'Subject:'
                        || subject
                        || lv_crlf));
         utl_smtp.write_raw_data ( l_mail_conn
    utl_raw.cast_to_raw ( lv_crlf
                        || message));
    utl_smtp.close_data(l_mail_conn);
         utl_smtp.quit(l_mail_conn);
         RETURN TRUE;
    EXCEPTION
         WHEN OTHERS
         THEN
              RETURN FALSE;
    END;

  • Sending Email from PL/SQL on Oracle 8.05...

    Hi,
    I need to send an email from PL/SQL, my database is on Windows
    server and it's 8.05 (sorry we're late on upgrading:(...)
    Thanks in advance
    Cecmlia

    Hello,
    Here is sample code for sending mail using PL/SQL.
    This PL/sql Procedure sends mails using SMTP server.
    Author - Mr. Adinath R. Kamode
    Date - 08/05/2001
    procedure sendmail is
    c utl_smtp.connection; -- Connectio type variable
    v_from varchar2(200);
    v_from1 varchar2(200);
    v_to varchar2(200);
    PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2)
    AS
    BEGIN
    -- Generates header data required from mail
    utl_smtp.write_data(c, name || ': ' || header ||
    utl_tcp.CRLF);
    END;
    begin
    c := utl_smtp.open_connection('smtp_server.pc150'); --
    Specify your SMTP -- server
    address here
    utl_smtp.helo(c, 'pc150');
    -- Define sender and receiver
    utl_smtp.mail(c, '[email protected]');
    utl_smtp.rcpt(c, '[email protected]');
    utl_smtp.open_data(c);
    send_header
    ('From','Sender<[email protected]>');
    send_header
    ('To', 'Recipient<[email protected]>');
    send_header('Subject', 'Hello');
    utl_smtp.write_data(c, utl_tcp.CRLF || 'Hello, world!');
    utl_smtp.close_data(c);
    utl_smtp.quit(c);
    end;
    Adi

  • Email to hotmail or yahoo from Database trigger

    Hi all.
    I m working on Oracle Developer 6i with Oracle 9i.
    OS is Windows XP. My Oracle database is on Samba Server.
    I m using Exchange Server as my mail server.
    I want to send emails to hotmail, yahoor or any other mail server from my company.
    I have already create a database procedure to send mails within my company.
    I m using following procedure.
    PROCEDURE send_mail(p_to IN VARCHAR2,
    p_subject IN VARCHAR2,
    p_body IN VARCHAR2,
    p_from IN VARCHAR2)
    IS
    con utl_smtp.connection;
    l_log_err varchar2(4000);
    PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) is
    BEGIN
    utl_smtp.write_data(con,name||': '||header||chr(13)||chr(10));
    END;
    BEGIN
    con := utl_smtp.open_connection(hd_parameter.setting('MAILSVR'));
    utl_smtp.helo(con,hd_parameter.setting('DOMAIN'));
    utl_smtp.mail(con, p_from);
    utl_smtp.rcpt(con, p_to);
    utl_smtp.open_data(con);
    send_header('From', 'Help Desk System');
    send_header('To', p_to);
    send_header('Subject', p_subject);
    utl_smtp.write_data(con,chr(13)||chr(10)||p_body);
    utl_smtp.close_data(con);
    utl_smtp.quit(con);
    EXCEPTION
    WHEN utl_smtp.transient_error or utl_smtp.permanent_error THEN
    BEGIN
    utl_smtp.quit(con);
    EXCEPTION
    WHEN utl_smtp.transient_error or utl_smtp.permanent_error THEN
    Null;
    END;
    /* Create the error log file if send mail fails
    Added: June 03, 2004 by Hassan Raza*/
    l_log_err := sqlerrm;
    insert into mail_log_error
    values(sysdate, 'Failed to send mail due to the following error:'||l_log_err);
    END;
    Best Regards
    Hassan

    Hi Justin
    I got the following error
    Failed to send mail due to the following error:ORA-29279: SMTP permanent error: 550 5.7.1 Unable to relay for [email protected]
    Failed to send mail due to the following error:ORA-29279: SMTP permanent error: 550 5.7.1 Unable to relay for [email protected]
    Can you help me what should i do in this case?
    Best Regards
    Hassan Raza

  • Automatic Procedure execution

    Hi All,
    I have following two questions. Can anyone help us please?
    1. Unlike Unix Cron job(which starts automatically at the specified time), is there any way I can have certain stored procedure executed automatically within Oracle server? Also if any failures in the execution(exceptions) I wold like to be notified by an email?
    2. If i have a Oracle DB account as scott/tiger@TEST and has a stored procedure with the name TEST_PROC(i_date date), how can I have this procedure called within a UNIX cron entry so that it gets executed at the specified date and time?
    Early reply...(as usual but it really will be highly appriciated since its somthing in production)..
    cheers
    sandeep

    Hi Sandeep
    Here is an example for sending email. Include this code in the exception handling part of your proc.
    DECLARE
    c utl_smtp.connection;
    PROCEDURE header(name IN VARCHAR2, header IN VARCHAR2) AS
    BEGIN
    utl_smtp.write_data(c, name || ': ' || header || utl_tcp.CRLF);
    END;
    BEGIN
    c := utl_smtp.open_connection('www.oracle.com');
    utl_smtp.helo(c, 'us.oracle.com');
    utl_smtp.mail(c, '[email protected]');
    utl_smtp.rcpt(c, '[email protected]');
    utl_smtp.open_data(c);
    header('From', '"Diwakar Sharma" <[email protected]>');
    header('To', '"Sandeep" <[email protected]>');
    header('Subject', 'Hello');
    utl_smtp.write_data(c, utl_tcp.crlf || 'Hello,' || utl_tcp.CRLF ||
    utl_tcp.CRLF ||
    'This is a test message.' || utl_tcp.CRLF || 'Diwakar');
    utl_smtp.close_data(c);
    utl_smtp.quit(c);
    END;
    Hope this helps
    Diwakar

  • Unix script in PL/SQL

    I am building a txt file using UTL_FILE in PL/SQL and need to email it using a Unix script. How can I add the Unix script to the end of the PL/SQL?

    Well, on the UNIX side of things I have simply used mail -s <subject> <email_address> < <text or file> to send mail inside of a UNIX script and it works fine.
    or you can use cat <some text> | mail -s <subject> <email_address>
    UTL_SMTP works well if you want to have less moving parts and have one script compiled inside the database. I guess if you already have the UTL_FILE working, it would be less work to just add in the code to mail from the UNIX script.
    HTH
    ReedK

  • Extending send_mail

    I am using this code (below) within a procedure and it is working great. But, I can not figure out the symantecs on how to add more than the two e-mails to the recipient list. Any help would be greatly appreciated.
    Thanks.
    Brian
    send_email( sender => '[email protected]',
    recipient => '[email protected]',
    add_recip => '[email protected]',
    subject => 'test',
    message => .....

    I found another alternative that you can try which purportedly allows you to use multiple recipients. This one I got from Metalink. I haven't tried it myself, but I assume it works. Here it is pasted below:
    From: Michael Devlin 11-Sep-02 13:12
    Subject: Re : utl_smtp for multiple recipients
    In case anyone is looking for the code to actually do this:
    (sender varchar2, recipient varchar2, subj varchar2, msg varchar2) is
    --(sender varchar2, recipient varchar2, subrecipient varchar2, subj varchar2, msg varchar2) is
    --v_OutPutFileHandle UTL_FILE.FILE_TYPE ;
    conn utl_smtp.connection;
    smtp_host varchar2(50) := 'fs-ajd03';
    port varchar2(2) := 25;
    --mesg varchar2(2000) := null;
    cr varchar2(2) := chr(10)||chr(13);
    subj_line varchar2(50);
    commaPos number(3) := 0;
    recipientlist varchar2(2000);
    subrecipient varchar2(50) := '';
    BEGIN
    --v_OutputFileHandle := UTL_FILE.FOPEN('c:\temp\', 'test1.txt', 'w');
    conn := utl_smtp.open_connection(smtp_host, port);
    utl_smtp.helo(conn, smtp_host);
    utl_smtp.mail(conn, sender);
    --UTL_FILE.PUT_LINE(v_OutputFileHandle, sender);
    UTL_FILE.PUT_LINE(v_OutputFileHandle, '---------------');
    --UTL_FILE.PUT_LINE(v_OutputFileHandle, recipient);
    commaPos := INSTR(recipient, ',');
    IF commaPos > 0 THEN
    recipientlist := recipient;
    LOOP
    subrecipient := SUBSTR(recipientlist, 1, INSTR(recipientlist, ',', 1, 1) - 1);
    --UTL_FILE.PUT_LINE(v_OutputFileHandle, subrecipient);
    utl_smtp.rcpt(conn, subrecipient);
    commaPos := INSTR(recipientlist, ',');
    recipientlist := LTRIM(SUBSTR(recipientlist, commaPos + 1));
    --UTL_FILE.PUT_LINE(v_OutputFileHandle, recipientlist);
    commaPos := INSTR(recipientlist, ',');
    IF commaPos = 0 THEN
    utl_smtp.rcpt(conn, recipientlist);
    EXIT;
    END IF;
    END LOOP;
    ELSE
    utl_smtp.rcpt(conn, recipient);
    END IF;
    utl_smtp.open_data(conn);
    subj_line := 'Subject: '||subj || cr;
    utl_smtp.write_data(conn, subj_line);
    --utl_smtp.write_data(conn, 'Date: ' || TO_CHAR( SYSDATE, 'dd-Mon-yy hh24:mi:ss' ) || cr);
    --utl_smtp.send_header(mail_conn,' ');
    utl_smtp.write_data(conn, msg);
    utl_smtp.close_data(conn);
    utl_smtp.quit(conn);
    --UTL_FILE.FCLOSE(v_OutputFileHandle);
    /*EXCEPTION
    WHEN UTL_FILE.INVALID_PATH THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20100, 'Reset: Invalid Path');
    WHEN UTL_FILE.INVALID_MODE THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20101, 'Reset: Invalid Mode');
    WHEN UTL_FILE.INVALID_OPERATION THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20101, 'Reset: Invalid Operation');
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20101, 'Reset: Invalid File Handle');
    WHEN VALUE_ERROR THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20101, 'Reset: Value Error');
    WHEN UTL_FILE.READ_ERROR THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20101, 'Reset: Read Error');
    WHEN UTL_FILE.INTERNAL_ERROR THEN
    UTL_FILE.FCLOSE(v_OutputFileHandle);
    RAISE_APPLICATION_ERROR(-20101, 'Reset: Internal Error');*/
    END;
    Michael P. Devlin
    Developer/Programmer
    A. James de Bruin & Sons
    [email protected]

Maybe you are looking for

  • [SOLVED] Installing VLC from Extras doesn't work.

    Hey guys, During installation I enabled the pacman repository mirror for my country. Which is hosted by Kangaroot.net Just now I tried to install VLC media player. Oddly enough pacman couldn't find a couple of dependency packages on the Kangaroot mir

  • After Lion Upgrade, External Display ( DVI ) Not detecting Monitor.

    This problem is on my Macbook Pro 17" 2006 (ish) intel core 2 duo. I have allways used the display port with a DVI cable connected to a DVI port on an external monitor to extend my desktop. For some reason after upgrading to Lion, I can't detect the

  • Case for macbook?

    i've read a couple complaints here that the incase neoprene case has left stains on some people's white macbook....any recs out there for one that will protect my case without staining it? thanks!

  • Oracle Connectivity to progress Database

    Hi, We have to make a direct connection between Oracle and Progress database on unix machines? Does anybody know how the connectivity can be configured/set up using ODBC drivers. Thanks in advance, null

  • Adobe and script causing slow run

    Every once in a while I get a spinning beach ball for about 10 seconds, then a box saying an Adobe Script is causing things to run slow, do I want to abort the script. I do and everything's fine. What is it that's happening? Should I trash Adobe Read