Skip to Main Content
  • Questions
  • Using email to acknowledge receipt of data submitted via a form -- v7.3 database

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Kum-Sung.

Asked: July 10, 2000 - 4:01 pm UTC

Last updated: February 18, 2007 - 8:19 pm UTC

Version: Forms 5.0, Reports 3.0

Viewed 1000+ times

You Asked

Dear Sir:

I am building a 3-tiered, web-based database application using Oracle 7.3.4 as the backend, Developer 2000 forms (version 5.0) as the front end, and Oracle Web Applications Server (OWAS 3.0) as the middle tier. The database is on a Unix Box (Data General) while the OWAS is on an NT box.

Our facility operators would use the deployed web form to submit environmental data to us via the Internet. For each submission received, I would like the application to automatically generate and send an email to the customer with an attached copy of the data received, much like what Amazon.com would do after you have successfully placed an order. We use GroupWise here for email.

How do I implement this functionality in Oracle? Please advise. Thanks.

and Tom said...

In 7.3, the solutions are limited. There are at least 3 I can think of right away (and have used all 3 at various points). By far, the easiest method is:

1) use a stored procedure to write an OS file. This OS file is the email. have a cron job run every N minutes to "push" the queue (deliver any files that appear in this directory and then get rid of them).

2) more complex but more 'immediate'. If you set up a cgi-bin script that can do an email on the OAS side -- such that if you had a form:

<form action=do_mail>
<input type=text name=to>
<input type=text name=subj>
<input type=text name=body>
<input type=submit>
</form>

it would work (and it would send "mail" to TO with a subject SUBJ and a body of BODY). You could write this cgi-bin in perl, shell, C, anything you wanted.

Now, you could write a stored procedure that executed:

resp := utl_http.request( '</code> HTTP://hostname/cgi-bin/do_mail?to=tkyte%40us.oracle.com&subj=Hi%20There&body=How%20are%20you%3F'
);


That would send the email for you by running the cgi-bin script.


Here is a small URLENCODE routine you can use to get all of the right escape characters for a URL:

create or replace function urlencode( p_str in varchar2 ) return varchar2
as
    l_tmp   varchar2(6000);
    l_len   number default length(p_str);
    l_hex   varchar2(16) default '0123456789ABCDEF';
    l_num   number;
    l_bad   varchar2(100) default ' >%}\~];?@&<#{|^[`/:=$+''"' || chr(10);
    l_char  char(1);
begin
    if ( p_str is NULL ) then
        return NULL;
    end if;

    for i in 1 .. length(p_str) loop
        l_char :=  substr(p_str,i,1);
        if ( instr( l_bad, l_char ) > 0 )
        then
            l_num := ascii( l_char );
            l_tmp := l_tmp || '%' ||
                substr(l_hex, mod(trunc(l_num/16),16)+1, 1 ) ||
                substr(l_hex, mod(l_num,   16)+1, 1 );
        else
            l_tmp := l_tmp || l_char;
        end if;
    end loop;

    return l_tmp;
end;
/


3) use database pipes to create a "pipe" daemon in C that can send mail as well. See 
http://asktom.oracle.com/~tkyte/plex/index.html <code>
for more info on that concept.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

capturing email address from web browser

ht, February 18, 2007 - 5:55 pm UTC

Hi Tom,
I'm using the owa_util package to grab info from a user's session. In the example above, is there a method to retrieve the user's email address (or other identifier such as network ID) from the session?

remote_addr gives me an ip address but the user may have multiple systems.

Also, I'm providing access to the public so a userid/password will not be required.

Thank you in advance.

ht
Tom Kyte
February 18, 2007 - 8:19 pm UTC

you have access to the stuff printed out by owa_util.print_cgi_env

their email address is typically not going to be there at all. thankfully. I wouldn't want you to be able to grab MY email address for example.

A reader, February 18, 2007 - 10:37 pm UTC


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library