?
Solved

Jserver and UTL_SMTP problem?

Posted on 2005-03-10
8
Medium Priority
?
1,188 Views
Last Modified: 2012-06-21

Hi there,

I am running a oracle 8.1.7.4 database on windows 2000 server and I am trying to get the UTL_SMTP package to work. I have created to procedure see bottom of page, but seem to be getting the the below error when I try and send a email. The user I am using is has full dba privlededges.

begin
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.security.AccessControlException: the Permission (java.net.SocketPermission
mail.twang.net resolve) has not been granted by dbms_java.grant_permission to
SchemaProtectionDomain(SYS|PolicyTableProxy(SYS))
ORA-06512: at "SYS.UTL_TCP", line 678
ORA-06512: at "SYS.UTL_TCP", line 247
ORA-06512: at "SYS.UTL_SMTP", line 99
ORA-06512: at "SYS.UTL_SMTP", line 121
ORA-06512: at "ED1.MAIL_PKG1", line 51
ORA-06512: at line 2

When I connect to sql/plus I get the following:

Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
With the Partitioning option
JServer Release 8.1.7.4.1 - Production

But when I do the following query:

select '   The '||parameter||' option is not installed'
from   sys.v_$option
where  value <> 'TRUE';

I get:

'THE'||PARAMETER||'OPTIONISNOTINSTALLED'
--------------------------------------------------------------------------------
   The Parallel Server option is not installed
   The Java option is not installed

It looks like Jserver has not been installed properly.

Can someone tell me how to reinstall Jserver so I will be able to send email?

TIA

Eddy

CREATE OR REPLACE PACKAGE BODY mail_pkg1 AS
   g_crlf      CHAR(2) DEFAULT chr(13) || chr(10);
   g_mail_conn utl_smtp.connection;
   g_mailhost  VARCHAR2(255) := 'mailserver';

   FUNCTION address_email(p_string IN VARCHAR2, p_recipients IN ARRAY)
      RETURN VARCHAR2 IS
      l_recipients LONG;
   BEGIN
      FOR i IN 1 .. p_recipients.COUNT
      LOOP
         utl_smtp.rcpt(g_mail_conn, p_recipients(i));
         IF (l_recipients IS NULL)
         THEN
            l_recipients := p_string || p_recipients(i);
         ELSE
            l_recipients := l_recipients || ', ' || p_recipients(i);
         END IF;
      END LOOP;
      RETURN l_recipients;
   END;

   PROCEDURE send(p_sender_email IN VARCHAR2
                 ,p_from         IN VARCHAR2 DEFAULT NULL
                 ,p_to           IN ARRAY DEFAULT ARRAY()
                 ,p_cc           IN ARRAY DEFAULT ARRAY()
                 ,p_bcc          IN ARRAY DEFAULT ARRAY()
                 ,p_subject      IN VARCHAR2 DEFAULT NULL
                 ,p_body         IN VARCHAR2 DEFAULT NULL
                 ,p_html         IN VARCHAR2 DEFAULT NULL) IS
      l_to_list  LONG;
      l_cc_list  LONG;
      l_bcc_list LONG;
      l_boundary   VARCHAR2(255) DEFAULT 'a1b2c3d4e3f2g1';
      l_body_html  CLOB := empty_clob; --This LOB will be the email message
      l_offset     NUMBER;
      l_ammount    NUMBER;
      l_temp       VARCHAR2(32767) DEFAULT NULL;
      l_date     VARCHAR2(255) DEFAULT to_char(SYSDATE,
                                               'dd Mon yy hh24:mi:ss');

      PROCEDURE writedata(p_text IN VARCHAR2) AS
      BEGIN
         IF (p_text IS NOT NULL)
         THEN
            utl_smtp.write_data(g_mail_conn, p_text || g_crlf);
         END IF;
      END;

   BEGIN
      g_mail_conn := utl_smtp.open_connection(g_mailhost, 25);

      utl_smtp.helo(g_mail_conn, g_mailhost);
      utl_smtp.mail(g_mail_conn, p_from);

      l_to_list  := address_email('To: ', p_to);
      l_cc_list  := address_email('Cc: ', p_cc);
      l_bcc_list := address_email('Bcc: ', p_bcc);

   l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);
   l_temp := l_temp || 'Content-Type: multipart/alternative; boundary=' ||
             chr(34) || l_boundary || chr(34) || chr(13) || chr(10);

   ----------------------------------------------------
   -- Write the headers
   dbms_lob.createtemporary(l_body_html, FALSE, 10);
   dbms_lob.WRITE(l_body_html, length(l_temp), 1, l_temp);

   ----------------------------------------------------
   -- Write the text boundary
   l_offset := dbms_lob.getlength(l_body_html) + 1;
   l_temp   := '--' || l_boundary || chr(13) || chr(10);
   l_temp   := l_temp || 'content-type: text/plain; charset=us-ascii' ||
               chr(13) || chr(10) || chr(13) || chr(10);
   dbms_lob.WRITE(l_body_html, length(l_temp), l_offset, l_temp);

   ----------------------------------------------------
   -- Write the plain text portion of the email
   l_offset := dbms_lob.getlength(l_body_html) + 1;
   dbms_lob.WRITE(l_body_html, length(p_body), l_offset, p_body);

   ----------------------------------------------------
   -- Write the HTML boundary
   l_temp   := chr(13) || chr(10) || chr(13) || chr(10) || '--' ||
               l_boundary || chr(13) || chr(10);
   l_temp   := l_temp || 'content-type: text/html;' || chr(13) || chr(10) ||
               chr(13) || chr(10);
   l_offset := dbms_lob.getlength(l_body_html) + 1;
   dbms_lob.WRITE(l_body_html, length(l_temp), l_offset, l_temp);

   ----------------------------------------------------
   -- Write the HTML portion of the message
   l_offset := dbms_lob.getlength(l_body_html) + 1;
   dbms_lob.WRITE(l_body_html, length(p_html), l_offset, p_html);

   ----------------------------------------------------
   -- Write the final html boundary
   l_temp   := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);
   l_offset := dbms_lob.getlength(l_body_html) + 1;
   dbms_lob.WRITE(l_body_html, length(l_temp), l_offset, l_temp);

   ----------------------------------------------------
   -- Send the email in 1900 byte chunks to UTL_SMTP
   l_offset  := 1;
   l_ammount := 1900;

   utl_smtp.open_data(g_mail_conn);

      writedata('Date: ' || l_date);
      writedata('From: ' || nvl(p_from, p_sender_email));
      writedata('Subject: ' || nvl(p_subject, '(no subject)'));

      writedata(l_to_list);
      writedata(l_cc_list);
      writedata(l_bcc_list);

      utl_smtp.write_data(g_mail_conn, '' || g_crlf);
   WHILE l_offset < dbms_lob.getlength(l_body_html)
   LOOP
      utl_smtp.write_data(g_mail_conn,
                          dbms_lob.substr(l_body_html, l_ammount, l_offset));
      l_offset  := l_offset + l_ammount;
      l_ammount := least(1900, dbms_lob.getlength(l_body_html) - l_ammount);
   END LOOP;
      utl_smtp.close_data(g_mail_conn);
      utl_smtp.quit(g_mail_conn);
   END;
END;

0
Comment
Question by:teched1000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 25

Expert Comment

by:jrb1
ID: 13511343
I just found a reference to an oracle bug which says that Java is no longer an option in oracle and that the value in v$option is always set to false although the option exists (after 8.1.6).  So I'll bet that's not your problem.
0
 
LVL 25

Assisted Solution

by:jrb1
jrb1 earned 750 total points
ID: 13511806
I see this listed as a solution:

  1) Logon as SYS or SYSTEM
  2) Issue the following commands :
     a) call dbms_java.grant_permission('<user>',
                                        'java.net.SocketPermission',
                                        'hostname',
                                        'resolve');
     b) commit;
         Note: Commit is mandatory !!
  3) Logoff as SYS or SYSTEM
  4) Retry your application

0
 

Author Comment

by:teched1000
ID: 13512247
Hi jrb1,

Thanks for the quick responce.

I will give it a go in the morning when my brain is working.

Thanks again

Eddy
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 48

Expert Comment

by:schwertner
ID: 13514696
Java Server needs some prerequisites to be installed correctly.
I do not know for 8i, but for 9i/10g it needs:
1. At least 10MB free in system table
2. Java pool at least 150 MB
3. shared pool at least 150 MB

It is hard task to deinstall and to install correctly Jserver.

You can give a try using the above prerequisites and running the script catpatch.sql
but I an sceptic you will install correctly Jserver.
0
 

Author Comment

by:teched1000
ID: 13515900

Hi jrb1,

I tried your suggesttion and I got:

  1* call dbms_java.grant_permission('ed1',) call dbms_java.grant_permission('edward_richards',
SP2-0734: unknown command beginning "'java.net...." - rest of line ignored.
SP2-0734: unknown command beginning "'hostname'..." - rest of line ignored.
SP2-0042: unknown command "'resolve')" - rest of line ignored.


definately logged in as sys as sysdba.

any ideas?

TIA

Eddy
0
 

Author Comment

by:teched1000
ID: 13516445

Hi schwertner,

I found out that I need:

1. 130MB free on the system tablespace
2. At least 70MB free shared_pool space needed
3. At least 50MB java_pool_size

I have increased the shared_pool_size, java_pool_size and system tablespace.

So if these were not set correctly when the database was created and Jserver installed then is it a corrupt installation?

Or is it just a matter of running a few scripts which will re-create the classes and packages?

TIA

Ed

0
 
LVL 48

Accepted Solution

by:
schwertner earned 750 total points
ID: 13517447
I found only for 9i:

http://www.oracle.com/technology/oramag/oracle/03-mar/o23support.html

May be seaarching on Google, AskTom, Oracle magazine you will be able to find how to do this for 8i.

As I recall one need to uninstall JVM before installing it again.
0
 

Author Comment

by:teched1000
ID: 13558676

Hi again schwertner and jrb1,

I have extended the java_pool_size and the shared_pool_size to the right size. Made sure that the rollback space of 100MB and space in the system for 130MB.

The odd thing is that when I count how many java classes I have I get:

SQL> select count (*) from user_objects where object_type='JAVA CLASS';

  COUNT(*)
----------
      9974

and when I see how many of them are acturally invalid:

SQL> select count(*) from user_objects
  2         where object_type='JAVA CLASS' and status != 'VALID';

  COUNT(*)
----------
         0

I am still getting:

SQL> call dbms_java.grant_permission('EDDY',
  2                                          'java.net.SocketPermission',
  3                                          'hostname',
  4                                          'resolve');
call dbms_java.grant_permission('EDDY',
     *
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.SecurityException: policy table update SYS:java.net.SocketPermission,
hostname

I really do not want to have to reload the JVM as this is a production database and is used round the clock.

I created another database but did not select to install JVM, I then installed JVM manually and the call works:

SQL> call dbms_java.grant_permission('EDDY',
  2                                          'java.net.SocketPermission',
  3                                          'hostname',
  4                                          'resolve');

Call completed.

any advise?


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question